<!DOCTYPE html>


    <html itemscope itemtype="http://schema.org/QAPage" class="html__responsive">

    <head>

        <title>html - RegEx match open tags except XHTML self-contained tags - Stack Overflow</title>
        <link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196">
        <link rel="apple-touch-icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a">
        <link rel="image_src" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a"> 
        <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
        <link rel="canonical" href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" />
        <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">
        <meta property="og:type" content= "website" />
        <meta property="og:url" content="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags"/>
        <meta property="og:site_name" content="Stack Overflow" />
        <meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=73d79a89bded" />
        <meta name="twitter:card" content="summary"/>
        <meta name="twitter:domain" content="stackoverflow.com"/>
        <meta name="twitter:title" property="og:title" itemprop="name" content="RegEx match open tags except XHTML self-contained tags" />
        <meta name="twitter:description" property="og:description" itemprop="description" content="I need to match all of these opening tags:&#xA;&#xA;&amp;lt;p&amp;gt;&#xA;&amp;lt;a href=&quot;foo&quot;&amp;gt;&#xD;&#xA;But not these:&#xA;&#xA;&amp;lt;br /&amp;gt;&#xA;&amp;lt;hr class=&quot;foo&quot; /&amp;gt;&#xD;&#xA;I came up with this and wanted to make sure I&#x27;ve got it right. I a..." />

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://cdn.sstatic.net/Js/stub.en.js?v=5ee3b0399cfd"></script>
    
        <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/stacks.css?v=0ee8a05683e7" >
        <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/stackoverflow/primary.css?v=fdb3d3b930f9" >

    
            <link rel="alternate" type="application/atom+xml" title="Feed for question &#x27;RegEx match open tags except XHTML self-contained tags&#x27;" href="/feeds/question/1732348">
            <meta name="twitter:app:country" content="US" />
            <meta name="twitter:app:name:iphone" content="Stack Exchange iOS" />
            <meta name="twitter:app:id:iphone" content="871299723" />
            <meta name="twitter:app:url:iphone" content="se-zaphod://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" />
            <meta name="twitter:app:name:ipad" content="Stack Exchange iOS" />
            <meta name="twitter:app:id:ipad" content="871299723" />
            <meta name="twitter:app:url:ipad" content="se-zaphod://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" />
            <meta name="twitter:app:name:googleplay" content="Stack Exchange Android">
            <meta name="twitter:app:url:googleplay" content="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags">
            <meta name="twitter:app:id:googleplay" content="com.stackexchange.marvin">
        <script>
            StackExchange.ready(function () {

                    StackExchange.using("snippets", function () {
                        StackExchange.snippets.initSnippetRenderer();
                    });
                    
                StackExchange.using("postValidation", function () {
                    StackExchange.postValidation.initOnBlurAndSubmit($('#post-form'), 2, 'answer');
                });


                StackExchange.question.init({showAnswerHelp:true,totalCommentCount:0,shownCommentCount:0,questionId:1732348});

                styleCode();

                    StackExchange.realtime.subscribeToQuestion('1', '1732348');
                    StackExchange.using("gps", function () { StackExchange.gps.trackOutboundClicks('#content', '.post-text'); });

                
                
            });
        </script>

        
        
        
        
        
        
        


    <script>
        StackExchange.init({"locale":"en","serverTime":1592589054,"routeName":"Questions/Show","stackAuthUrl":"https://stackauth.com","networkMetaHostname":"meta.stackexchange.com","site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers","isNoticesTabEnabled":true,"enableNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"id":1,"childUrl":"https://meta.stackoverflow.com","negativeVoteScoreFloor":null,"enableSocialMediaInSharePopup":true,"protocol":"https"},"user":{"fkey":"f4b78665943d49f72333c3d80d4c7823069e60242e13087f67ce62e267f9013f","tid":"69755307-9311-68c2-0848-82c854a0f32e","rep":0,"isAnonymous":true,"isAnonymousNetworkWide":true,"ab":{"tutorial_tooltips":{"v":"thanks_reaction_icon","g":1}}},"events":{"postType":{"question":1},"postEditionSection":{"title":1,"body":2,"tags":3}},"story":{"minCompleteBodyLength":75,"likedTagsMaxLength":300,"dislikedTagsMaxLength":300},"jobPreferences":{"maxNumDeveloperRoles":2,"maxNumIndustries":4},"svgIconPath":"https://cdn.sstatic.net/Img/svg-icons","svgIconHash":"7aa1e7a5b07a"}, {"userProfile":{"openGraphAPIKey":"4a307e43-b625-49bb-af15-ffadf2bda017"},"userMessaging":{"showNewFeatureNotice":true},"tags":{},"subscriptions":{"defaultMaxTrueUpSeats":1000},"snippets":{"renderDomain":"stacksnippets.net","snippetsEnabled":true},"slack":{"sidebarAdDismissCookie":"slack-sidebar-ad","sidebarAdDismissCookieExpirationDays":60.0},"site":{"allowImageUploads":true,"enableImgurHttps":true,"enableUserHovercards":true,"forceHttpsImages":true,"styleCode":true},"paths":{},"monitoring":{"clientTimingsAbsoluteTimeout":30000,"clientTimingsDebounceTimeout":1000},"mentions":{"maxNumUsersInDropdown":50},"markdown":{"asteriskIntraWordEmphasis":true},"flags":{"allowRetractingCommentFlags":true,"allowRetractingFlags":true},"comments":{},"accounts":{"currentPasswordRequiredForChangingStackIdPassword":true}});
        StackExchange.using.setCacheBreakers({"js/adops.en.js":"22a9bd59b1e9","js/ask.en.js":"635d2cc64f27","js/begin-edit-event.en.js":"011a1d228ca8","js/events.en.js":"da72fc77b277","js/explore-qlist.en.js":"222b04ca33bc","js/full-anon.en.js":"24abb6888af7","js/full.en.js":"ada34f05dd4d","js/help.en.js":"b66b9c5b699c","js/inline-tag-editing.en.js":"3c6b83c6e552","js/keyboard-shortcuts.en.js":"6dc8506386b0","js/mobile.en.js":"8ff5a2e24dd9","js/moderator.en.js":"95481dba6974","js/postCollections-transpiled.en.js":"1d6aeeec3a16","js/post-validation.en.js":"1033e1de5a27","js/prettify-full.en.js":"241e50860e5e","js/question-editor.en.js":"","js/review.en.js":"e1a9346d1d1a","js/revisions.en.js":"d8d5fa1f473d","js/tageditor.en.js":"efe5b5954fe6","js/tageditornew.en.js":"f43de26e2a59","js/tagsuggestions.en.js":"a9ff449efcdc","js/wmd.en.js":"40acadf1f713","js/snippet-javascript-codemirror.en.js":"61bebf415a81"});
        StackExchange.using("gps", function() {
             StackExchange.gps.init(true);
        });
    </script>
    <noscript id="noscript-css"><style>body,.top-bar{margin-top:1.9em}</style></noscript>
    </head>
    <body class="question-page unified-theme">
    <div id="notify-container"></div>
    <div id="custom-header"></div>
        
<header class="top-bar js-top-bar top-bar__network _fixed">
    <div class="wmx12 mx-auto grid ai-center h100" role="menubar">
        <div class="-main grid--cell">
                <a href="#" class="left-sidebar-toggle p0 ai-center jc-center js-left-sidebar-toggle" role="menuitem" aria-haspopup="true" aria-controls="left-sidebar" aria-expanded="false"><span class="ps-relative"></span></a>
                <div class="topbar-dialog leftnav-dialog js-leftnav-dialog dno">
                    <div class="left-sidebar js-unpinned-left-sidebar" data-can-be="left-sidebar" data-is-here-when="sm"></div>
                </div>
                    <a href="https://stackoverflow.com" class="-logo js-gps-track"
                        data-gps-track="top_nav.click({is_current:false, location:2, destination:8})">
                        <span class="-img _glyph">Stack Overflow</span>
                    </a>



        </div>

            <ol class="list-reset grid gs4" role="presentation">
                <li class="grid--cell">
                    <a href="#"
                        class="-marketing-link js-gps-track js-products-menu"
                        aria-controls="products-popover"
                        data-controller="s-popover"
                        data-action="s-popover#toggle"
                        data-s-popover-placement="bottom"
                        data-s-popover-toggle-class="is-selected"
                        data-gps-track="top_nav.products.click({location:2, destination:1})"
                        data-ga="[&quot;top navigation&quot;,&quot;products menu click&quot;,null,null,null]">
                        Products
                    </a>
                </li>

                    <li class="grid--cell md:d-none">
                        <a href="/teams/customers" class="-marketing-link js-gps-track"
                           data-gps-track="top_nav.products.click({location:2, destination:7})"
                            data-ga="[&quot;top navigation&quot;,&quot;customers menu click&quot;,null,null,null]">Customers</a>
                    </li>
                    <li class="grid--cell md:d-none">
                        <a href="/teams/use-cases" class="-marketing-link js-gps-track"
                           data-gps-track="top_nav.products.click({location:2, destination:8})"
                           data-ga="[&quot;top navigation&quot;,&quot;use cases menu click&quot;,null,null,null]">Use cases</a>
                    </li>
            </ol>
            <div class="s-popover ws2 p6"
                    id="products-popover"
                    role="menu"
                    aria-hidden="true">
                <div class="s-popover--arrow"></div>
                <ol class="list-reset s-anchors s-anchors__inherit">
                    <li>
                        <a href="/questions" class="d-block py6 px6 bar-sm h:bg-black-100 js-gps-track"
                           data-gps-track="top_nav.products.click({location:2, destination:2})"
                           data-ga="[&quot;top navigation&quot;,&quot;public qa submenu click&quot;,null,null,null]">
                            <span class="fs-body1 d-block">Stack Overflow</span>
                            <span class="fs-caption d-block fc-light">Public questions and answers</span>
                        </a>
                    </li>
                    <li>
                        <a href="/teams" class="d-block py6 px6 bar-sm h:bg-black-100 js-gps-track"
                           data-gps-track="top_nav.products.click({location:2, destination:3})"
                           data-ga="[&quot;top navigation&quot;,&quot;teams submenu click&quot;,null,null,null]">
                            <span class="fs-body1 d-block">Teams</span>
                            <span class="fs-caption d-block fc-light">Private questions and answers for your team</span>
                        </a>
                    </li>
                    <li>
                        <a href="/enterprise" class="d-block py6 px6 bar-sm h:bg-black-100 js-gps-track"
                           data-gps-track="top_nav.products.click({location:2, destination:4})"
                           data-ga="[&quot;top navigation&quot;,&quot;enterprise submenu click&quot;,null,null,null]">
                            <span class="fs-body1 d-block">Enterprise</span>
                            <span class="fs-caption d-block fc-light">Private self-hosted questions and answers for your enterprise</span>
                        </a>
                    </li>
                    <li>
                        <a href="/jobs?so_source=ProductsMenu&so_medium=StackOverflow" class="d-block py6 px6 bar-sm h:bg-black-100 js-gps-track"
                            data-gps-track="top_nav.products.click({location:2, destination:9})"
                            data-ga="[&quot;top navigation&quot;,&quot;jobs submenu click&quot;,null,null,null]">
                            <span class="fs-body1 d-block">Jobs</span>
                            <span class="fs-caption d-block fc-light">Programming and related technical career opportunities</span>
                        </a>
                    </li>
                    <li class="bt bc-black-3 mln6 mrn6 mt6 pt6 px6" >
                        <a href="https://stackoverflow.com/talent" class="d-block py6 px6 bar-sm h:bg-black-100 js-gps-track"
                           data-gps-track="top_nav.products.click({location:2, destination:5})"
                           data-ga="[&quot;top navigation&quot;,&quot;talent submenu click&quot;,null,null,null]">
                            <span class="fs-body1 d-block">Talent</span>
                            <span class="fs-caption d-block fc-light">Hire technical talent</span>
                        </a>
                    </li>
                    <li>
                        <a href="https://stackoverflow.com/advertising" class="d-block py6 px6 bar-sm h:bg-black-100 js-gps-track"
                           data-gps-track="top_nav.products.click({location:2, destination:6})"
                           data-ga="[&quot;top navigation&quot;,&quot;advertising submenu click&quot;,null,null,null]">
                            <span class="fs-body1 d-block">Advertising</span>
                            <span class="fs-caption d-block fc-light">Reach developers worldwide</span>
                        </a>
                    </li>

                </ol>
            </div>

            <form id="search" role="search" action=/search method="get" class="grid--cell fl-grow1 searchbar px12 js-searchbar " autocomplete="off">
                    <div class="ps-relative">
                        <input name="q"
                               type="text"
                               placeholder="Search&#x2026;"
                               value=""
                               autocomplete="off"
                               maxlength="240"
                               class="s-input s-input__search js-search-field "
                               aria-label="Search"
                               aria-controls="top-search" 
                               data-controller="s-popover"
                               data-action="focus->s-popover#show"
                               data-s-popover-placement="bottom-start"/>
                        <svg aria-hidden="true" class="s-input-icon s-input-icon__search svg-icon iconSearch" width="18" height="18" viewBox="0 0 18 18"><path d="M18 16.5l-5.14-5.18h-.35a7 7 0 10-1.19 1.19v.35L16.5 18l1.5-1.5zM12 7A5 5 0 112 7a5 5 0 0110 0z"/></svg>
                        <div class="s-popover p0 wmx100 wmn4 sm:wmn-initial js-top-search-popover s-popover--arrow__tl" id="top-search" role="menu">
    <div class="js-spinner p24 grid ai-center jc-center d-none">
        <div class="s-spinner s-spinner__sm fc-orange-400">
            <div class="v-visible-sr">Loading&#x2026;</div>
        </div>
    </div>

    <span class="v-visible-sr js-screen-reader-info"></span>
    <div class="js-ac-results overflow-y-auto hmx3 d-none"></div>

    <div class="js-search-hints" aria-describedby="Tips for searching"></div>
</div>
                    </div>
            </form>
        
        

<ol class="overflow-x-auto ml-auto -secondary grid ai-center list-reset h100 user-logged-out" role="presentation">
        <li class="-item searchbar-trigger"><a href="#" class="-link js-searchbar-trigger" role="button" aria-label="Search" aria-haspopup="true" aria-controls="search" title="Click to show search"><svg aria-hidden="true" class="svg-icon iconSearch" width="18" height="18" viewBox="0 0 18 18"><path d="M18 16.5l-5.14-5.18h-.35a7 7 0 10-1.19 1.19v.35L16.5 18l1.5-1.5zM12 7A5 5 0 112 7a5 5 0 0110 0z"/></svg></a></li>

            <li class="-ctas">
                            <a href="https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f1732348%2fregex-match-open-tags-except-xhtml-self-contained-tags%3fanswertab%3dvotes" class="login-link s-btn s-btn__filled py8 js-gps-track" rel="nofollow"
                               data-gps-track="login.click" data-ga="[&quot;top navigation&quot;,&quot;login button click&quot;,null,null,null]">Log in</a>
                            <a href="https://stackoverflow.com/users/signup?ssrc=head&returnurl=%2fusers%2fstory%2fcurrent" class="login-link s-btn s-btn__primary py8" rel="nofollow" data-ga="[&quot;sign up&quot;,&quot;Sign Up Navigation&quot;,&quot;Header&quot;,null,null]">Sign up</a>

            </li>

    <li class="js-topbar-dialog-corral" role="presentation">
            

    <div class="topbar-dialog siteSwitcher-dialog dno" role="menu">
        <div class="header">
            <h3>
                <a href="https://stackoverflow.com">current community</a>
            </h3>
        </div>
        <div class="modal-content bg-powder-050">
            <ul class="current-site">
                    <li class="grid">
                            <div class="fl1">
                <a href="https://stackoverflow.com"
       class="current-site-link site-link js-gps-track grid gs8 gsx"
       data-id="1"
       data-gps-track="site_switcher.click({ item_type:3 })">
        <div class="favicon favicon-stackoverflow site-icon grid--cell" title="Stack Overflow"></div>
        <span class="grid--cell fl1">
            Stack Overflow
        </span>
    </a>

    </div>
    <div class="related-links">
            <a href="https://stackoverflow.com/help" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:14 })">help</a>
            <a href="https://chat.stackoverflow.com" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:6 })">chat</a>
    </div>

                    </li>
                    <li class="related-site grid">
                            <div class="L-shaped-icon-container">
        <span class="L-shaped-icon"></span>
    </div>

                            <a href="https://meta.stackoverflow.com"
       class=" site-link js-gps-track grid gs8 gsx"
       data-id="552"
       data-gps-track="site.switch({ target_site:552, item_type:3 }),site_switcher.click({ item_type:4 })">
        <div class="favicon favicon-stackoverflowmeta site-icon grid--cell" title="Meta Stack Overflow"></div>
        <span class="grid--cell fl1">
            Meta Stack Overflow
        </span>
    </a>

                    </li>
            </ul>
        </div>

        <div class="header" id="your-communities-header">
            <h3>
your communities            </h3>

        </div>
        <div class="modal-content" id="your-communities-section">

                <div class="call-to-login">
<a href="https://stackoverflow.com/users/signup?ssrc=site_switcher&amp;returnurl=%2fusers%2fstory%2fcurrent" class="login-link js-gps-track" data-gps-track="site_switcher.click({ item_type:10 })">Sign up</a> or <a href="https://stackoverflow.com/users/login?ssrc=site_switcher&amp;returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f1732348%2fregex-match-open-tags-except-xhtml-self-contained-tags%3fanswertab%3dvotes" class="login-link js-gps-track" data-gps-track="site_switcher.click({ item_type:11 })">log in</a> to customize your list.                </div>
        </div>

        <div class="header">
            <h3><a href="https://stackexchange.com/sites">more stack exchange communities</a>
            </h3>
            <a href="https://stackoverflow.blog" class="fr">company blog</a>
        </div>
        <div class="modal-content">
                <div class="child-content"></div>
        </div>        
    </div>

    </li>
</ol>
    </div>
</header>
    <div id="js-gdpr-consent-banner" class="p8 ff-sans ps-fixed b0 l0 r0 z-banner" role="banner" aria-hidden="false" style="background-color: #3b4045; color: white;"> 
        <div class="wmx8 mx-auto grid grid__center" role="alertdialog" aria-describedby="notice-message">
            <div class="grid--cell mr12" aria-label="notice-message">
                <p class="mb0 lh-lg">
                    By using our site, you acknowledge that you have read and understand our <a class="s-link s-link__inherit td-underline fc-white" target="_blank" href="https://stackoverflow.com/legal/cookie-policy">Cookie Policy</a>, <a class="s-link s-link__inherit td-underline fc-white" target="_blank" href="https://stackoverflow.com/legal/privacy-policy">Privacy Policy</a>, and our <a class="s-link s-link__inherit td-underline fc-white" target="_blank" href="https://stackoverflow.com/legal/terms-of-service/public">Terms of Service</a>.
                </p>
            </div>
            <div class="grid--cell">
                <a class="s-btn s-btn__muted s-btn__icon js-notice-close" aria-label="notice-dismiss">
                    <svg aria-hidden="true" class="svg-icon iconClear" width="18" height="18" viewBox="0 0 18 18"><path d="M15 4.41L13.59 3 9 7.59 4.41 3 3 4.41 7.59 9 3 13.59 4.41 15 9 10.41 13.59 15 15 13.59 10.41 9 15 4.41z"/></svg>
                </a>
            </div>
        </div>
    </div>

    <script>
        StackExchange.ready(function () { StackExchange.topbar.init(); });
StackExchange.scrollPadding.setPaddingTop(50, 10);    </script>





    <div class="container">
            

<div id="left-sidebar" data-is-here-when="md lg" class="left-sidebar js-pinned-left-sidebar ps-relative">
    <div class="left-sidebar--sticky-container js-sticky-leftnav">
        <nav role="navigation">
            <ol class="nav-links">
        <li class="">
            <a
                href="/"
                class="pl8 js-gps-track nav-links--link"
                
                data-gps-track="top_nav.click({is_current:false, location:2, destination:8})">
Home            </a>
        </li>
                <li>
                    <ol class="nav-links">
                            <li class="fs-fine tt-uppercase ml8 mt16 mb4 fc-light">Public</li>
                                <li class=" youarehere">
            <a id="nav-questions"
                href="/questions"
                class="pl8 js-gps-track nav-links--link -link__with-icon"
                
                data-gps-track="top_nav.click({is_current:true, location:2, destination:1})">
<svg aria-hidden="true" class="svg-icon iconGlobe" width="18" height="18" viewBox="0 0 18 18"><path d="M9 1a8 8 0 100 16A8 8 0 009 1zM8 15.32a6.4 6.4 0 01-5.23-7.75L7 11.68v.8c0 .88.12 1.32 1 1.32v1.52zm5.72-2c-.2-.66-1-1.32-1.72-1.32h-1v-2c0-.44-.56-1-1-1H6V7h1c.44 0 1-.56 1-1V5h2c.88 0 1.4-.72 1.4-1.6v-.33a6.4 6.4 0 012.32 10.24v.01z"/></svg>                    <span class="-link--channel-name">Stack Overflow</span>
            </a>
        </li>

        <li class="">
            <a id="nav-tags"
                href="/tags"
                class=" js-gps-track nav-links--link"
                
                data-gps-track="top_nav.click({is_current:false, location:2, destination:2})">
Tags            </a>
        </li>
        <li class="">
            <a id="nav-users"
                href="/users"
                class=" js-gps-track nav-links--link"
                
                data-gps-track="top_nav.click({is_current:false, location:2, destination:3})">
Users            </a>
        </li>
        <li class="">
            <a id="nav-jobs"
                href="/jobs?so_medium=StackOverflow&amp;so_source=SiteNav"
                class=" js-gps-track nav-links--link"
                
                data-gps-track="top_nav.click({is_current:false, location:2, destination:6})">
Jobs            </a>
        </li>
                    </ol>
                </li>
                    <li>
                        <ol class="nav-links">
                                <li class="grid ai-center jc-space-between ml8 mt24 mb4">
                                    <div class="grid--cell tt-uppercase fs-fine fc-light">Teams</div>
                                    <div class="grid--cell fs-fine fc-light mr4">
                                        <a href="javascript:void(0)" class="s-link s-link__inherit js-gps-track"
                                            role="button"
                                            aria-controls="popover-teams-create-cta"
                                            data-controller="s-popover"
                                            data-action="s-popover#toggle"
                                            data-s-popover-placement="bottom-start"
                                            data-s-popover-toggle-class="is-selected"
                                            data-gps-track="teams.create.left-sidenav.click({ Action: ShowInfo })"
                                            data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav show teams info&quot;,null,null,null]">
                                            What&#x2019;s this?
                                        </a>

                                    </div>
                                </li>
                                <li class="ps-relative">
                                    <a href="https://stackoverflow.com/teams"
                                        class="pl8 js-gps-track nav-links--link"
                                        title="Stack Overflow for Teams is a private, secure spot for your organization's questions and answers."
                                        data-gps-track="teams.create.left-sidenav.click({ Action: TeamsClick })"
                                        data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav team click&quot;,&quot;stackoverflow.com/teams&quot;,null,null]">
                                        <div class="grid ai-center">
                                            <div class="grid--cell s-avatar va-middle bg-orange-400">
                                                <div class="s-avatar--letter mtn1">
                                                    <svg aria-hidden="true" class="svg-icon iconBriefcaseSm" width="14" height="14" viewBox="0 0 14 14"><path d="M4 3a1 1 0 011-1h4a1 1 0 011 1v1h.5c.83 0 1.5.67 1.5 1.5v5c0 .83-.67 1.5-1.5 1.5h-7A1.5 1.5 0 012 10.5v-5C2 4.67 2.67 4 3.5 4H4V3zm5 1V3H5v1h4z"/></svg>
                                                </div>
                                                <svg aria-hidden="true" class="native s-avatar--badge svg-icon iconShieldXSm" width="9" height="10" viewBox="0 0 9 10"><path d="M0 1.84L4.5 0 9 1.84v3.17C9 7.53 6.3 10 4.5 10 2.7 10 0 7.53 0 5.01V1.84z" fill="var(--white)"/><path d="M1 2.5L4.5 1 8 2.5v2.51C8 7.34 5.34 9 4.5 9 3.65 9 1 7.34 1 5.01V2.5zm2.98 3.02L3.2 7h2.6l-.78-1.48a.4.4 0 01.15-.38c.34-.24.73-.7.73-1.14 0-.71-.5-1.23-1.41-1.23-.92 0-1.39.52-1.39 1.23 0 .44.4.9.73 1.14.12.08.18.23.15.38z" fill="var(--black-500)"/></svg>
                                            </div>
                                            <div class="grid--cell pl6">
Free 30 Day Trial                                            </div>
                                        </div>
                                    </a>
                                </li>
                        </ol>
                    </li>
            </ol>
        </nav>
    </div>


        <div class="s-popover w-auto p16"
             id="popover-teams-create-cta"
             role="menu"
             aria-hidden="true">
            <div class="s-popover--arrow"></div>

            <div class="ps-relative overflow-hidden">
                <p class="mb2"><strong>Teams</strong></p>
                <p class="mb16 fs-caption fc-medium">Q&amp;A for Work</p>
                <p class="mb8 fs-caption fc-medium">

                            Stack Overflow for Teams is a private, secure spot for you and
                            your coworkers to find and share information.
                                        </p>
                <a href="https://stackoverflow.com/teams"
                   class="js-gps-track ws-nowrap d-block"
                   data-gps-track="teams.create.left-sidenav.click({ Action: CtaClick })"
                   data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav cta&quot;,&quot;stackoverflow.com/teams&quot;,null,null]">
Learn more                </a>
            </div>

            <div class="ps-absolute t8 r8">
                <svg width="53" height="49" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M49 11l.2 31H18.9L9 49v-7H4V8h31" fill="#CCEAFF" /><path d="M44.5 19v-.3l-.2-.1-18-13-.1-.1H.5v33h4V46l.8-.6 9.9-6.9h29.3V19z" stroke="#1060E1" stroke-miterlimit="10" /><path d="M31 2l6-1.5 7 2V38H14.9L5 45v-7H1V6h25l5-4z" fill="#fff" /><path d="M7 16.5h13m-13 6h14m-14 6h18" stroke="#1060E1" stroke-miterlimit="10" /><path d="M39 30a14 14 0 1 0 0-28 14 14 0 0 0 0 28z" fill="#FFB935" /><path d="M50.5 14a13.5 13.5 0 1 1-27 0 13.5 13.5 0 0 1 27 0z" stroke="#F48024" stroke-miterlimit="10" /><path d="M32.5 21.5v-8h9v8h-9zm2-9.5V9.3A2.5 2.5 0 0 1 37 6.8a2.5 2.5 0 0 1 2.5 2.5V12h-5zm2 3v2m1-2v2" stroke="#fff" stroke-miterlimit="10" /></svg>
            </div>
        </div>

</div>



        <div id="content" class="snippet-hidden">

            
<div itemprop="mainEntity" itemscope itemtype="http://schema.org/Question">
    <link itemprop="image" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a">

    <div class="inner-content clearfix">

        

            <div id="question-header" class="grid sm:fd-column">
                        <h1 itemprop="name" class="grid--cell fs-headline1 fl1 ow-break-word mb8"><a href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" class="question-hyperlink">RegEx match open tags except XHTML self-contained tags</a></h1>

                <div class="ml12 aside-cta grid--cell print:d-none sm:ml0 sm:mb12 sm:order-first sm:as-end">
                    
    <a href="/questions/ask" class="ws-nowrap s-btn s-btn__primary" >
        Ask Question
    </a>

                </div>
            </div>
            <div class="grid fw-wrap pb8 mb16 bb bc-black-2">
                    <div class="grid--cell ws-nowrap mr16 mb8" title="2009-11-13 22:38:26Z">
                        <span class="fc-light mr2">Asked</span>
                        <time itemprop="dateCreated" datetime="2009-11-13T22:38:26">10 years, 7 months ago</time>
                    </div>
                        <div class="grid--cell ws-nowrap mr16 mb8">
                            <span class="fc-light mr2">Active</span>
                            <a href="?lastactivity" class="s-link s-link__inherit" title="2020-06-04 02:20:16Z">15 days ago</a>
                        </div>
                    <div class="grid--cell ws-nowrap mb8" title="Viewed 2,866,006 times">
                        <span class="fc-light mr2">Viewed</span>
                        2.9m times
                    </div>
            </div>
            <div id="mainbar" role="main" aria-label="question and answers">

                
<div class="question" data-questionid="1732348"  id="question">
    <style>.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
            margin-bottom:0;
}
</style>
<div id="dfp-tlb" class="everyonelovesstackoverflow everyoneloves__top-leaderboard mb8 mx-auto"></div>

    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1732348">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this question if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="1484">1484</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this question if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

        <button class="js-bookmark-btn s-btn s-btn__unset c-pointer py4 js-gps-track" 
                data-controller="s-tooltip" data-s-tooltip-placement="right" title="Bookmark this question."
                aria-pressed="false" aria-label="Bookmark (6519)" data-selected-classes="fc-yellow-600"
                data-gps-track="post.click({ item: 1, priv: 0, post_type: 1 })">
            <svg aria-hidden="true" class="svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M6 1a2 2 0 00-2 2v14l5-4 5 4V3a2 2 0 00-2-2H6zm3.9 3.83h2.9l-2.35 1.7.9 2.77L9 7.59l-2.35 1.7.9-2.76-2.35-1.7h2.9L9 2.06l.9 2.77z"/></svg>
            <div class="js-bookmark-count mt4" data-value="6519">6519</div>
        </button>
    

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732348/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="postcell post-layout--right">
    
    <div class="post-text" itemprop="text">
                        <div>
            <aside class="s-notice s-notice__info js-post-notice mb16" role="status">
        <div class="grid fd-column fw-nowrap">
            <div class="grid fw-nowrap">
                    <div class="grid--cell mr8">
                        <svg aria-hidden="true" class="svg-icon iconLock" width="18" height="18" viewBox="0 0 18 18"><path d="M16 9a2 2 0 00-2-2V6A5 5 0 004 6v1a2 2 0 00-2 2v6c0 1.1.9 2 2 2h10a2 2 0 002-2V9zm-7 5a2 2 0 110-4 2 2 0 010 4zm3.1-7H5.9V6a3.1 3.1 0 016.2 0v1z"/></svg>
                    </div>
                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        <b>Locked</b>. Comments on this question have been disabled, but it is still accepting new answers and other interactions. <a href="/help/locked-posts">Learn more</a>.
                        
                    </div>
                </div>
            </div>
        </div>
</aside>

    </div>

<p>I need to match all of these opening tags:</p>

<pre><code>&lt;p&gt;
&lt;a href="foo"&gt;
</code></pre>

<p>But not these:</p>

<pre><code>&lt;br /&gt;
&lt;hr class="foo" /&gt;
</code></pre>

<p>I came up with this and wanted to make sure I've got it right. I am only capturing the <code>a-z</code>.</p>

<pre><code>&lt;([a-z]+) *[^/]*?&gt;
</code></pre>

<p>I believe it says:</p>

<ul>
<li>Find a less-than, then</li>
<li>Find (and capture) a-z one or more times, then</li>
<li>Find zero or more spaces, then</li>
<li>Find any character zero or more times, greedy, except <code>/</code>, then</li>
<li>Find a greater-than</li>
</ul>

<p>Do I have that right? And more importantly, what do you think?</p>
    </div>

        <div class="post-taglist grid gs4 gsy fd-column">
            <div class="grid ps-relative d-block">
                <a href="/questions/tagged/html" class="post-tag" title="show questions tagged &#39;html&#39;" rel="tag">html</a> <a href="/questions/tagged/regex" class="post-tag" title="show questions tagged &#39;regex&#39;" rel="tag">regex</a> <a href="/questions/tagged/xhtml" class="post-tag" title="show questions tagged &#39;xhtml&#39;" rel="tag">xhtml</a> 
            </div>
        </div>

    <div class="mb0 ">
        <div class="mt16 grid gs8 gsy fw-wrap jc-end ai-start pt4">
            <div class="grid--cell mr16" style="flex: 1 1 100px;">
                

<div class="post-menu">
    <a href="/q/1732348"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this question"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 1 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this question"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="question"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="1"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1732348/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 1 })" title="">improve this question</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1732348" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-question js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 1 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this question to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

            </div>

                <div class="post-signature grid--cell">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732348/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 1 })">edited <span title="2012-05-26 20:37:05Z" class="relativetime">May 26 '12 at 20:37</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>                </div>
            <div class="post-signature grid--cell">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732348" href="/posts/1732348/revisions" title="show revision history for this post">
        11 revs, 7 users 58%<br><a href="/users/142233">Jeff</a>

        </a>
    </div>
</div>

            </div>
        </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1732348" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="1732348" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="false"
                    data-comments-unavailable="true"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1732348" data-rep=50 data-anon=true>
                    <span class="disabled-link">comments disabled on deleted / locked posts / reviews</span>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>


<div id="dfp-isb" class="everyonelovesstackoverflow everyoneloves__inline-sidebar mt24 mx-auto"></div>

                <div id="answers">

                    <a name="tab-top"></a>
                    <div id="answers-header">
                        <div class="answers-subheader grid ai-center mb8">
                            <div class="grid--cell fl1">
                                <h2 class="mb0" data-answercount="35">
                                        35 Answers
                                    <span style="display:none;" itemprop="answerCount">35</span>
                                </h2>
                            </div>
                            <div class="grid--cell">
                                <div class=" grid s-btn-group js-filter-btn">
        <a class="grid--cell s-btn s-btn__muted s-btn__outlined" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?answertab=active#tab-top" data-nav-xhref="" title="Answers with the latest activity first" data-value="active" data-shortcut="A">
            Active</a>
        <a class="grid--cell s-btn s-btn__muted s-btn__outlined" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?answertab=oldest#tab-top" data-nav-xhref="" title="Answers in the order they were provided" data-value="oldest" data-shortcut="O">
            Oldest</a>
        <a class="youarehere is-selected grid--cell s-btn s-btn__muted s-btn__outlined" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?answertab=votes#tab-top" data-nav-xhref="" title="Answers with the highest score first" data-value="votes" data-shortcut="V">
            Votes</a>
</div>

                            </div>
                        </div>
                            
                    </div>

<div class="s-pagination pager-answers">
<div class="s-pagination--item is-selected">1</div>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=votes#tab-top" rel="" title="Go to page 2">2</a>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=votes#tab-top" rel="next" title="Go to page 2"> Next</a></div>

                                          
<a name="1732454"></a>
<div id="answer-1732454" class="answer accepted-answer" data-answerid="1732454"  itemprop="acceptedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1732454">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="4416">4416</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732454/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
                    <div>
            <aside class="s-notice s-notice__info js-post-notice mb16" role="status">
        <div class="grid fd-column fw-nowrap">
            <div class="grid fw-nowrap">
                    <div class="grid--cell mr8">
                        <svg aria-hidden="true" class="svg-icon iconLock" width="18" height="18" viewBox="0 0 18 18"><path d="M16 9a2 2 0 00-2-2V6A5 5 0 004 6v1a2 2 0 00-2 2v6c0 1.1.9 2 2 2h10a2 2 0 002-2V9zm-7 5a2 2 0 110-4 2 2 0 010 4zm3.1-7H5.9V6a3.1 3.1 0 016.2 0v1z"/></svg>
                    </div>
                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        <b>Locked</b>. There are <a href="/help/locked-posts">disputes about this answer’s content</a> being resolved at this time. It is not currently accepting new interactions.
                        
                    </div>
                </div>
            </div>
        </div>
</aside>

    </div>

<p>You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by HTML. HTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down HTML into its meaningful parts. so many times but it is not getting to me. Even enhanced irregular regular expressions as used by Perl are not up to the task of parsing HTML. You will never make me crack. HTML is a language of sufficient complexity that it cannot be parsed by regular expressions. Even Jon Skeet cannot parse HTML using regular expressions. Every time you attempt to parse HTML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp. Parsing HTML with regex summons tainted souls into the realm of the living. HTML and regex go together like love, marriage, and ritual infanticide. The &lt;center> cannot hold it is too late. The force of regex and HTML together in the same conceptual space will destroy your mind like so much watery putty. If you parse HTML with regex you are giving in to Them and their blasphemous ways which doom us all to inhuman toil for the One whose Name cannot be expressed in the Basic Multilingual Plane, he comes. HTML-plus-regexp will liquify the n​erves of the sentient whilst you observe, your psyche withering in the onslaught of horror. Rege̿̔̉x-based HTML parsers are the cancer that is killing StackOverflow <i>it is too late it is too late we cannot be saved</i> the trangession of a chi͡ld ensures regex will consume all living tissue (except for HTML which it cannot, as previously prophesied) <i>dear lord help us how can anyone survive this scourge</i> using regex to parse HTML has doomed humanity to an eternity of dread torture and security holes <i>using rege</i>x as a tool to process HTML establishes a brea<i>ch between this world</i> and the dread realm of c͒ͪo͛ͫrrupt entities (like SGML entities, but <i>more corrupt) a mere glimp</i>se of the world of reg​<b>ex parsers for HTML will ins</b>​tantly transport a p<i>rogrammer's consciousness i</i>nto a w<i>orl</i>d of ceaseless screaming, he comes<strike>, the pestilent sl</strike>ithy regex-infection wil​<b>l devour your HT</b>​ML parser, application and existence for all time like Visual Basic only worse <i>he comes he com</i>es <i>do not fi</i>​ght h<b>e com̡e̶s, ̕h̵i</b>​s un̨ho͞ly radiańcé de<i>stro҉ying all enli̍̈́̂̈́ghtenment, HTML tags <b>lea͠ki̧n͘g fr̶ǫm ̡yo​͟ur eye͢s̸ ̛l̕ik͏e liq</b>​uid p</i>ain, the song of re̸gular exp​re<strike>ssion parsing </strike>will exti<i>​nguish the voices of mor​<b>tal man from the sp</b>​here I can see it can you see ̲͚̖͔̙î̩́t̲͎̩̱͔́̋̀ it is beautiful t​</i>he f<code>inal snuf</code>fing o<i>f the lie​<b>s of Man ALL IS LOŚ͖̩͇̗̪̏̈́T A</b></i><b>LL I​S L</b>OST th<i>e pon̷y he come</i>s he c̶̮om<strike>es he co</strike><b><strike>me</strike>s t<i>he</i> ich​</b>or permeat<i>es al</i>l MY FAC<i>E MY FACE ᵒh god n<b>o NO NOO̼</b></i><b>O​O N</b>Θ stop t<i>he an​*̶͑̾̾​̅ͫ͏̙̤g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨ</i>e̠̅s<code> ͎a̧͈͖r̽̾̈́͒͑e</code> n<b>​ot rè̑ͧ̌aͨl̘̝̙̃ͤ͂̾̆ ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ T</b>O͇̹̺ͅƝ̴ȳ̳ TH̘<b>Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝</b>S̨̥̫͎̭ͯ̿̔̀ͅ</p>

<hr>

<p>Have you tried using an XML parser instead?</p>

<hr>

<blockquote>
  <p><strong>Moderator's Note</strong></p>
  
  <p>This post is locked to prevent inappropriate edits to its content. The post looks exactly as it is supposed to look - there are no problems with its content. Please do not flag it for our attention.</p>
</blockquote>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-13T23:04:30"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1732454"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1732454" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732454/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2014-07-09 03:07:06Z" class="relativetime">Jul 9 '14 at 3:07</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732454" href="/posts/1732454/revisions" title="show revision history for this post">
        7 revs, 5 users 36%<br><a href="/users/18936">bobince</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1732454" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1732454" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="false"
                    data-comments-unavailable="true"
                    data-addlink-disabled="true">

                        <li id="comment-1612336" class="comment js-comment " data-comment-id="1612336">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">179</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Kobi: I think it&#39;s time for me to quit the post of Assistant Don&#39;t Parse HTML With Regex Officer. No matter how many times we say it, they won&#39;t stop coming every day... every hour even. It is a lost cause, which someone else can fight for a bit. So go on, parse HTML with regex, if you must. It&#39;s only broken code, not life and death.</span>
                
&ndash;&nbsp;<a href="/users/18936/bobince"
                       title="478,501 reputation"
                       class="comment-user">bobince</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-13 23:18:03Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 13 '09 at 23:18</span></span>
            </div>
        </div>
    </li>
    <li id="comment-1632978" class="comment js-comment " data-comment-id="1632978">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">27</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Is it possible to use RegEx to parse this answer?</span>
                
&ndash;&nbsp;<a href="/users/13495/chris-porter"
                       title="3,307 reputation"
                       class="comment-user">Chris Porter</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-17 18:26:15Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 17 '09 at 18:26</span></span>
            </div>
        </div>
    </li>
    <li id="comment-1647711" class="comment js-comment " data-comment-id="1647711">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">If you can&#39;t see this post, here&#39;s a screencapture of it in all its glory: <a href="http://imgur.com/gOPS2.png" rel="nofollow noreferrer">imgur.com/gOPS2.png</a></span>
                
&ndash;&nbsp;<a href="/users/68086/andrew-keeton"
                       title="17,291 reputation"
                       class="comment-user">Andrew Keeton</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-19 14:37:27Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 19 '09 at 14:37</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1732454" data-rep=50 data-anon=true>
                    <span class="disabled-link">comments disabled on deleted / locked posts / reviews</span>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

<div id="dfp-mlb" class="everyonelovesstackoverflow everyoneloves__mid-leaderboard my8 mx-auto"></div>
                                          
<a name="1733489"></a>
<div id="answer-1733489" class="answer" data-answerid="1733489"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1733489">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="3253">3253</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>
            
<div class="js-bounty-award-container grid--cell pb4">

    <div class="grid fd-column gs4 ai-center">

            <div class="js-bounty-award grid--cell s-badge s-badge__bounty s-badge__sm as-center"
                 title="This answer has been awarded bounties worth 50 reputation by ThiefMaster" data-controller="s-tooltip" data-s-tooltip-placement="right">
                +50
            </div>

    </div>
</div>


        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1733489/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>While <em>arbitrary</em> HTML with only a regex is impossible, it's sometimes appropriate to use them for parsing a <em>limited, known</em> set of HTML.  </p>

<p>If you have a small set of HTML pages that you want to scrape data from and then stuff into a database, regexes might work fine.  For example, I recently wanted to get the names, parties, and districts of Australian federal Representatives, which I got off of the Parliament's web site.  This was a limited, one-time job.  </p>

<p>Regexes worked just fine for me, and were very fast to set up.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-14T06:27:19"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1733489"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 4.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1733489/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1733489" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1733489/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2019-09-19 15:30:40Z" class="relativetime">Sep 19 '19 at 15:30</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1733489" href="/posts/1733489/revisions" title="show revision history for this post">
        10 revs, 10 users 36%<br><a href="/users/210931">Kaitlin Duck Sherwood</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1733489" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1733489" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="31"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-13095248" class="comment js-comment " data-comment-id="13095248">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">131</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Also, scraping fairly regularly formatted data from large documents is going to be WAY faster with judicious use of scan &amp; regex than any generic parser. And if you are comfortable with coding regexes, way faster to code than coding xpaths. And almost certainly less fragile to changes in what you are scraping. So bleh.</span>
                
&ndash;&nbsp;<a href="/users/173542/michael-johnston"
                       title="4,950 reputation"
                       class="comment-user">Michael Johnston</a>
                <span class="comment-date" dir="ltr"><span title="2012-04-17 20:47:27Z, License: CC BY-SA 3.0" class="relativetime-clean">Apr 17 '12 at 20:47</span></span>
            </div>
        </div>
    </li>
    <li id="comment-15088991" class="comment js-comment " data-comment-id="15088991">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">256</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@MichaelJohnston &quot;Less fragile&quot;? Almost certainly not. Regexes care about text-formatting details than an XML parser can silently ignore. Switching between <code>&amp;foo;</code> encodings and <code>CDATA</code> sections? Using an HTML minifier to remove all whitespace in your document that the browser doesn&#39;t render? An XML parser won&#39;t care, and neither will a well-written XPath statement. A regex-based &quot;parser&quot;, on the other hand...</span>
                
&ndash;&nbsp;<a href="/users/14122/charles-duffy"
                       title="211,777 reputation"
                       class="comment-user">Charles Duffy</a>
                <span class="comment-date" dir="ltr"><span title="2012-07-11 16:03:24Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 11 '12 at 16:03</span></span>
            </div>
        </div>
    </li>
    <li id="comment-15115534" class="comment js-comment " data-comment-id="15115534">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">41</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@CharlesDuffy for an one time job it&#39;s ok, and for spaces we use \s+</span>
                
&ndash;&nbsp;<a href="/users/1090657/quantum"
                       title="3,146 reputation"
                       class="comment-user">quantum</a>
                <span class="comment-date" dir="ltr"><span title="2012-07-12 13:50:01Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 12 '12 at 13:50</span></span>
            </div>
        </div>
    </li>
    <li id="comment-15120388" class="comment js-comment " data-comment-id="15120388">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">69</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@xiaomao indeed, if having to know all the gotchas and workarounds to get an 80% solution that fails the rest of the time &quot;works for you&quot;, I can&#39;t stop you. Meanwhile, I&#39;m over on my side of the fence using parsers that work on 100% of syntactically valid XML.</span>
                
&ndash;&nbsp;<a href="/users/14122/charles-duffy"
                       title="211,777 reputation"
                       class="comment-user">Charles Duffy</a>
                <span class="comment-date" dir="ltr"><span title="2012-07-12 16:07:28Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 12 '12 at 16:07</span></span>
            </div>
        </div>
    </li>
    <li id="comment-16523188" class="comment js-comment " data-comment-id="16523188">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">375</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I once had to pull some data off ~10k pages, all with the same HTML template. They were littered with HTML errors that caused parsers to choke, and all their styling was inline or with <code>&lt;font&gt;</code> etc.: no classes or IDs to help navigate the DOM. After fighting all day with the &quot;right&quot; approach, I finally switched to a regex solution and had it working in an hour.</span>
                
&ndash;&nbsp;<a href="/users/122087/paul-a-jungwirth"
                       title="19,272 reputation"
                       class="comment-user">Paul A Jungwirth</a>
                <span class="comment-date" dir="ltr"><span title="2012-09-07 07:14:38Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 7 '12 at 7:14</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1733489" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>31</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1758162"></a>
<div id="answer-1758162" class="answer" data-answerid="1758162"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1758162">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="2043">2043</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1758162/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>I think the flaw here is that HTML is a <a href="http://en.wikipedia.org/wiki/Context-free_grammar" rel="noreferrer">Chomsky Type 2 grammar (context free grammar)</a> and RegEx is a <a href="http://en.wikipedia.org/wiki/Regular_grammar" rel="noreferrer">Chomsky Type 3 grammar (regular grammar)</a>. Since a Type 2 grammar is fundamentally more complex than a Type 3 grammar (see the <a href="http://en.wikipedia.org/wiki/Chomsky_hierarchy" rel="noreferrer">Chomsky hierarchy</a>), it is <em>mathematically impossible</em> to parse XML with RegEx. </p>

<p>But many will try, some will even claim success - but until others find the fault and totally mess you up.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-18T18:42:40"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1758162"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 4.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1758162/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1758162" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1758162/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2018-11-19 15:50:21Z" class="relativetime">Nov 19 '18 at 15:50</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1758162" href="/posts/1758162/revisions" title="show revision history for this post">
        8 revs, 7 users 24%<br><a href="/users/22088">Vlad Gudim</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1758162" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1758162" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="10"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-12073546" class="comment js-comment " data-comment-id="12073546">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">226</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">The OP is asking to parse a very limited subset of XHTML: start tags. What makes (X)HTML a CFG is its potential to have elements between the start and end tags of other elements (as in a grammar rule <code>A -&gt; s A e</code>). (X)HTML does <i>not</i> have this property <i>within</i> a start tag: a start tag cannot contain other start tags. The subset that the OP is trying to parse is not a CFG.</span>
                
&ndash;&nbsp;<a href="/users/423105/larsh"
                       title="24,446 reputation"
                       class="comment-user">LarsH</a>
                <span class="comment-date" dir="ltr"><span title="2012-03-02 08:43:55Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 2 '12 at 8:43</span></span>
            </div>
        </div>
    </li>
    <li id="comment-12448141" class="comment js-comment " data-comment-id="12448141">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">101</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">In CS theory, regular languages <i>are</i> a strict subset of context-free languages, but regular expression implementations in mainstream programming languages are more powerful.  As <a href="http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/" rel="nofollow noreferrer">noulakaz.net/weblog/2007/03/18/&hellip;</a> describes, so-called &quot;regular expressions&quot; can check for prime numbers in unary, which is certainly something that a regular expression from CS theory can&#39;t accomplish.</span>
                
&ndash;&nbsp;<a href="/users/960195/adam-mihalcin"
                       title="12,758 reputation"
                       class="comment-user">Adam Mihalcin</a>
                <span class="comment-date" dir="ltr"><span title="2012-03-19 23:50:52Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 19 '12 at 23:50</span></span>
            </div>
        </div>
    </li>
    <li id="comment-13885068" class="comment js-comment " data-comment-id="13885068">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">11</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@eyelidlessness: the same &quot;only if&quot; applies to all CFGs, does it not? I.e. if the (X)HTML input is not well-formed, not even a full-blown XML parser will work reliably. Maybe if you give examples of the &quot;(X)HTML syntax errors implemented in real world user agents&quot; you&#39;re referring to, I&#39;ll understand what you&#39;re getting at better.</span>
                
&ndash;&nbsp;<a href="/users/423105/larsh"
                       title="24,446 reputation"
                       class="comment-user">LarsH</a>
                <span class="comment-date" dir="ltr"><span title="2012-05-22 05:09:22Z, License: CC BY-SA 3.0" class="relativetime-clean">May 22 '12 at 5:09</span></span>
            </div>
        </div>
    </li>
    <li id="comment-14106691" class="comment js-comment " data-comment-id="14106691">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">82</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@AdamMihalcin is exactly right. Most extant regex engines are more powerful than Chomsky Type 3 grammars (eg non-greedy matching, backrefs). Some regex engines (such as Perl&#39;s) are Turing complete. It&#39;s true that even those are poor tools for parsing HTML, but this oft-cited argument is not the reason why.</span>
                
&ndash;&nbsp;<a href="/users/272427/dubiousjim"
                       title="4,256 reputation"
                       class="comment-user">dubiousjim</a>
                <span class="comment-date" dir="ltr"><span title="2012-05-31 13:44:04Z, License: CC BY-SA 3.0" class="relativetime-clean">May 31 '12 at 13:44</span></span>
            </div>
        </div>
    </li>
    <li id="comment-22995858" class="comment js-comment " data-comment-id="22995858">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">27</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">This is the most &quot;full and short&quot; answer here. It leads people to learn basics of formal grammars and languages and hopefully some maths so they will not wast time on hopeless things like solving NP-tasks in polynomial time</span>
                
&ndash;&nbsp;<a href="/users/639353/mishmashru"
                       title="376 reputation"
                       class="comment-user">mishmashru</a>
                <span class="comment-date" dir="ltr"><span title="2013-04-19 12:15:57Z, License: CC BY-SA 3.0" class="relativetime-clean">Apr 19 '13 at 12:15</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1758162" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>10</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

<div id="dfp-smlb" class="everyonelovesstackoverflow everyoneloves__mid-second-leaderboard my8 mx-auto"></div>
                                          
<a name="5236278"></a>
<div id="answer-5236278" class="answer" data-answerid="5236278"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="5236278">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="1335">1335</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/5236278/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>Don't listen to these guys. You totally <strong>can</strong> parse context-free grammars with regex if you break the task into smaller pieces. You can generate the correct pattern with a script that does each of these in order: </p>

<ol>
<li>Solve the Halting Problem.</li>
<li>Square a circle.</li>
<li>Work out the Traveling Salesman Problem in O(log n) or less. If it's any more than that, you'll run out of RAM and the engine will hang.</li>
<li>The pattern will be pretty big, so make sure you have an algorithm that losslessly compresses random data.</li>
<li>Almost there - just divide the whole thing by zero. Easy-peasy.</li>
</ol>

<p>I haven't quite finished the last part myself, but I know I'm getting close. It keeps throwing <code>CthulhuRlyehWgahnaglFhtagnException</code>s for some reason, so I'm going to port it to VB 6 and use <code>On Error Resume Next</code>. I'll update with the code once I investigate this strange door that just opened in the wall. Hmm.</p>

<p>P.S. Pierre de Fermat also figured out how to do it, but the margin he was writing in wasn't big enough for the code.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2011-03-08T17:49:29"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/5236278"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 4.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/5236278/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-5236278" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/5236278/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2018-08-30 16:52:54Z" class="relativetime">Aug 30 '18 at 16:52</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Mar 8 &#39;11 at 17:49. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-5236278" href="/posts/5236278/revisions" title="show revision history for this post">
        10 revs<br><a href="/users/399649">Justin Morgan</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-5236278" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="5236278" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="14"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-14424307" class="comment js-comment " data-comment-id="14424307">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">80</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Divison by zero is a much easier problem than the others you mention. If you use intervals, rather than plain floating point arithmetic (which everyone should be but nobody is), you can happily divide something by [an interval containing] zero. The result is simply an interval containing plus and minus infinity.</span>
                
&ndash;&nbsp;<a href="/users/3408/rjmunro"
                       title="23,452 reputation"
                       class="comment-user">rjmunro</a>
                <span class="comment-date" dir="ltr"><span title="2012-06-14 10:53:39Z, License: CC BY-SA 3.0" class="relativetime-clean">Jun 14 '12 at 10:53</span></span>
            </div>
        </div>
    </li>
    <li id="comment-21359004" class="comment js-comment " data-comment-id="21359004">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">148</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Fermat&#39;s small margin problem has been solved by soft margins in modern text-editing software.</span>
                
&ndash;&nbsp;<a href="/users/820321/kd4ttc"
                       title="903 reputation"
                       class="comment-user">kd4ttc</a>
                <span class="comment-date" dir="ltr"><span title="2013-03-01 20:24:32Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 1 '13 at 20:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-41473537" class="comment js-comment " data-comment-id="41473537">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">50</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Fermat&#39;s small margin problem has been solved by Randall Munroe by setting the fontsize to zero: <a href="http://xkcd.com/1381/" rel="nofollow noreferrer">xkcd.com/1381</a></span>
                
&ndash;&nbsp;<a href="/users/401828/heltonbiker"
                       title="21,076 reputation"
                       class="comment-user">heltonbiker</a>
                <span class="comment-date" dir="ltr"><span title="2014-10-16 19:55:17Z, License: CC BY-SA 3.0" class="relativetime-clean">Oct 16 '14 at 19:55</span></span>
            </div>
        </div>
    </li>
    <li id="comment-44568333" class="comment js-comment " data-comment-id="44568333">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">29</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">FYI: Fermat&#39;s problem <a href="https://en.wikipedia.org/wiki/Wiles%27_proof_of_Fermat%27s_Last_Theorem" rel="nofollow noreferrer">has <i>actually</i> been solved in 1995</a>, and it only took mathematicians 358 years to do so.</span>
                
&ndash;&nbsp;<a href="/users/202504/jmiserez"
                       title="2,497 reputation"
                       class="comment-user">jmiserez</a>
                <span class="comment-date" dir="ltr"><span title="2015-01-22 18:40:17Z, License: CC BY-SA 3.0" class="relativetime-clean">Jan 22 '15 at 18:40</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-59460768" class="comment js-comment " data-comment-id="59460768">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">10</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I was able to bypass that sticky divide-by-zero step by instead using Brownian ratchets yielded from cold fusion...though it only works when I remove the cosmological constant.</span>
                
&ndash;&nbsp;<a href="/users/880904/tim-lehner"
                       title="13,265 reputation"
                       class="comment-user">Tim Lehner</a>
                <span class="comment-date" dir="ltr"><span title="2016-03-09 18:52:43Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 9 '16 at 18:52</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-5236278" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>14</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1736801"></a>
<div id="answer-1736801" class="answer" data-answerid="1736801"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1736801">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="1074">1074</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1736801/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p><strong>Disclaimer</strong>: use a parser if you have the option. That said...</p>

<p>This is the regex I use (!) to match HTML tags:</p>

<pre><code>&lt;(?:"[^"]*"['"]*|'[^']*'['"]*|[^'"&gt;])+&gt;
</code></pre>

<p>It may not be perfect, but I ran this code through a <em>lot</em> of HTML. Note that it even catches strange things like <code>&lt;a name="badgenerator""&gt;</code>, which show up on the web.</p>

<p>I guess to make it not match self contained tags, you'd either want to use <a href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732395#1732395">Kobi</a>'s negative look-behind:</p>

<pre><code>&lt;(?:"[^"]*"['"]*|'[^']*'['"]*|[^'"&gt;])+(?&lt;!/\s*)&gt;
</code></pre>

<p>or just combine if and if not.</p>

<p><strong>To downvoters:</strong> This is working code from an actual product. I doubt anyone reading this page will get the impression that it is socially acceptable to use regexes on HTML. </p>

<p><strong>Caveat</strong>: I should note that this regex still breaks down in the presence of CDATA blocks, comments, and script and style elements. Good news is, you can get rid of those using a regex...  </p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-15T06:37:18"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1736801"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1736801/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1736801" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1736801/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2017-05-23 12:34:53Z" class="relativetime">May 23 '17 at 12:34</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1736801" href="/posts/1736801/revisions" title="show revision history for this post">
        5 revs, 2 users 92%<br><a href="/users/7581">itsadok</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1736801" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1736801" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="4"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-13616563" class="comment js-comment " data-comment-id="13616563">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">95</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I would go with something that works on sane things than weep about not being universally perfect :-)</span>
                
&ndash;&nbsp;<a href="/users/1176394/prajeesh-kumar"
                       title="1,756 reputation"
                       class="comment-user">prajeesh kumar</a>
                <span class="comment-date" dir="ltr"><span title="2012-05-10 03:44:49Z, License: CC BY-SA 3.0" class="relativetime-clean">May 10 '12 at 3:44</span></span>
            </div>
        </div>
    </li>
    <li id="comment-21369558" class="comment js-comment " data-comment-id="21369558">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">55</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Is someone using CDATA inside HTML?</span>
                
&ndash;&nbsp;<a href="/users/531954/danubian-sailor"
                       title="21,010 reputation"
                       class="comment-user">Danubian Sailor</a>
                <span class="comment-date" dir="ltr"><span title="2013-03-02 07:51:55Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 2 '13 at 7:51</span></span>
            </div>
        </div>
    </li>
    <li id="comment-22995936" class="comment js-comment " data-comment-id="22995936">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">17</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">so you do not actually solve the parsing problem with regexp only but as a part of the parser this may work. PS: working product doesn&#39;t mean good code. No offence, but this is how industrial programming works and gets their money</span>
                
&ndash;&nbsp;<a href="/users/639353/mishmashru"
                       title="376 reputation"
                       class="comment-user">mishmashru</a>
                <span class="comment-date" dir="ltr"><span title="2013-04-19 12:18:30Z, License: CC BY-SA 3.0" class="relativetime-clean">Apr 19 '13 at 12:18</span></span>
            </div>
        </div>
    </li>
    <li id="comment-35875284" class="comment js-comment " data-comment-id="35875284">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">32</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Your regex starts fail on the very shortest possible, valid HTML: <code>&lt;!doctype html&gt;&lt;title&gt;&lt;&lt;&#47;title&gt;</code>. Simple <code>&#39;&lt;!doctype html&gt;&lt;title&gt;&lt;&lt;&#47;title&gt;&#39;.match(&#47;&lt;(?:&quot;[^&quot;]*&quot;[&#39;&quot;]*|&#39;[^&#39;]*&#39;[&#39;&quot;]*|[^&#39;&quot;&gt;])+&gt;&#47;g)</code> returns <code>[&quot;&lt;!doctype html&gt;&quot;, &quot;&lt;title&gt;&quot;, &quot;&lt;&lt;&#47;title&gt;&quot;]</code> while should <code>[&quot;&lt;title&gt;&quot;, &quot;&lt;&#47;title&gt;&quot;]</code>.</span>
                
&ndash;&nbsp;<span class="comment-user">user1180790</span>
                <span class="comment-date" dir="ltr"><span title="2014-05-01 16:48:11Z, License: CC BY-SA 3.0" class="relativetime-clean">May 1 '14 at 16:48</span></span>
            </div>
        </div>
    </li>
    <li id="comment-36631031" class="comment js-comment " data-comment-id="36631031">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">if we&#39;re just trying to match &amp; not match the examples given, /&lt;.([^r&gt;][^&gt;]*)?&gt;/g works :-) // javascript:  &#39;&lt;p&gt; &lt;a href=&quot;foo&quot;&gt; &lt;br /&gt; &lt;hr class=&quot;foo&quot; /&gt;&#39;.match(/&lt;.([^r&gt;][^&gt;]*)?&gt;/g)</span>
                
&ndash;&nbsp;<a href="/users/358236/imma"
                       title="4,492 reputation"
                       class="comment-user">imma</a>
                <span class="comment-date" dir="ltr"><span title="2014-05-22 16:14:26Z, License: CC BY-SA 3.0" class="relativetime-clean">May 22 '14 at 16:14</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1736801" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>4</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="5233151"></a>
<div id="answer-5233151" class="answer" data-answerid="5233151"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="5233151">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="506">506</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/5233151/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>There are people that will tell you that the Earth is round (or perhaps that the Earth is an oblate spheroid if they want to use strange words). They are lying. </p>

<p>There are people that will tell you that Regular Expressions shouldn't be recursive. They are limiting you. They need to subjugate you, and they do it by keeping you in ignorance.</p>

<p>You can live in their reality or take the red pill.</p>

<p>Like Lord Marshal (is he a relative of the Marshal .NET class?), I have seen the <strike>Underverse</strike> Stack Based Regex-Verse and returned with <strike>powers</strike> knowledge you can't imagine. Yes, I think there were an Old One or two protecting them, but they were watching football on the TV, so it wasn't difficult.</p>

<p>I think the XML case is quite simple. The RegEx (in the .NET syntax), deflated and coded in base64 to make it easier to comprehend by your feeble mind, should be something like this: </p>

<pre><code>7L0HYBxJliUmL23Ke39K9UrX4HShCIBgEyTYkEAQ7MGIzeaS7B1pRyMpqyqBymVWZV1mFkDM7Z28
995777333nvvvfe6O51OJ/ff/z9cZmQBbPbOStrJniGAqsgfP358Hz8itn6Po9/3eIue3+Px7/3F
86enJ8+/fHn64ujx7/t7vFuUd/Dx65fHJ6dHW9/7fd/t7fy+73Ye0v+f0v+Pv//JnTvureM3b169
OP7i9Ogyr5uiWt746u+BBqc/8dXx86PP7tzU9mfQ9tWrL18d3UGnW/z7nZ9htH/y9NXrsy9fvPjq
i5/46ss3p4z+x3e8b452f9/x93a2HxIkH44PpgeFyPD6lMAEHUdbcn8ffTP9fdTrz/8rBPCe05Iv
p9WsWF788Obl9MXJl0/PXnwONLozY747+t7x9k9l2z/4vv4kqo1//993+/vf2kC5HtwNcxXH4aOf
LRw2z9/v8WEz2LTZcpaV1TL/4c3h66ex2Xv95vjF0+PnX744PbrOm59ZVhso5UHYME/dfj768H7e
Yy5uQUydDAH9+/4eR11wHbqdfPnFF6cv3ogq/V23t++4z4620A13cSzd7O1s/77rpw+ePft916c7
O/jj2bNnT7e/t/397//M9+ibA/7s6ZNnz76PP0/kT2rz/Ts/s/0NArvziYxVEZWxbm93xsrUfnlm
rASN7Hf93u/97vvf+2Lx/e89L7+/FSXiz4Bkd/hF5mVq9Yik7fcncft9350QCu+efkr/P6BfntEv
z+iX9c4eBrFz7wEwpB9P+d9n9MfuM3yzt7Nzss0/nuJfbra3e4BvZFR7z07pj3s7O7uWJM8eCkme
nuCPp88MfW6kDeH7+26PSTX8vu+ePAAiO4LVp4zIPWC1t7O/8/+pMX3rzo2KhL7+8s23T1/RhP0e
vyvm8HbsdmPXYDVhtpdnAzJ1k1jeufOtUAM8ffP06Zcnb36fl6dPXh2f/F6nRvruyHfMd9rgJp0Y
gvsRx/6/ZUzfCtX4e5hTndGzp5jQo9e/z+s3p1/czAUMlts+P3tz+uo4tISd745uJxvb3/v4ZlWs
mrjfd9SG/swGPD/6+nh+9MF4brTBRmh1Tl5+9eT52ckt5oR0xldPzp7GR8pfuXf5PWJv4nJIwvbH
W3c+GY3vPvrs9zj8Xb/147/n7/b7/+52DD2gsSH8zGDvH9+i9/fu/PftTfTXYf5hB+9H7P1BeG52
MTtu4S2cTAjDizevv3ry+vSNb8N+3+/1po2anj4/hZsGt3TY4GmjYbEKDJ62/pHB+3/LmL62wdsU
1J18+eINzTJr3dMvXr75fX7m+MXvY9XxF2e/9+nTgPu2bgwh5U0f7u/74y9Pnh6/OX4PlA2UlwTn
xenJG8L996VhbP3++PCrV68QkrjveITxr2TIt+lL+f3k22fPn/6I6f/fMqZvqXN/K4Xps6sazUGZ
GeQlar49xEvajzI35VRevDl78/sc/b7f6jkG8Va/x52N4L9lBe/kZSh1hr9fPj19+ebbR4AifyuY
12efv5CgGh9TroR6Pj2l748iYxYgN8Z7pr0HzRLg66FnRvcjUft/45i+pRP08vTV6TOe2N/9jv37
R9P0/5YxbXQDeK5E9R12XdDA/4zop+/9Ht/65PtsDVlBBUqko986WsDoWqvbPD2gH/T01DAC1NVn
3/uZ0feZ+T77fd/GVMkA4KjeMcg6RcvQLRl8HyPaWVStdv17PwHV0bOB9xUh7rfMp5Zu3icBJp25
D6f0NhayHyfI3HXHY6YYCw7Pz17fEFhQKzS6ZWChrX+kUf7fMqavHViEPPKjCf1/y5hukcyPTvjP
mHQCppRDN4nbVFPaT8+ekpV5/TP8g/79mVPo77PT1/LL7/MzL7548+XvdfritflFY00fxIsvSQPS
mvctdYZpbt7vxKRfj3018OvC/hEf/79lTBvM3debWj+b8KO0wP+3OeM2aYHumuCAGonmCrxw9cVX
X1C2d4P+uSU7eoBUMzI3/f9udjbYl/el04dI7s8fan8dWRjm6gFx+NrKeFP+WX0CxBdPT58df/X8
DaWLX53+xFdnr06f/szv++NnX7x8fnb6NAhIwsbPkPS7iSUQAFETvP2Tx8+/Og0Xt/yBvDn9vd/c
etno8S+81QKXptq/ffzKZFZ+4e/743e8zxino+8RX37/k595h5/H28+y7fPv490hQdJ349E+txB3
zPZ5J/jsR8bs/y1j2hh/2fkayOqEmYcej0cXUWMN7QrqBwjDrVZRfyQM3xjj/EgYvo4wfLTZrnVS
ebdKq0XSZJvzajKQDUv1/P3NwbEP7cN5+Odivv9/ysPfhHfkOP6b9Fl+91v7LD9aCvp/+Zi+7lLQ
j0zwNzYFP+/Y6r1NcFeDbfBIo8rug3zS3/3WPumPlN3/y8f0I2X3cz4FP+/Y6htSdr2I42fEuSPX
/ewpL4e9/n1evzn94hb+Plpw2+dnbyh79zx0CsPvbq0lb+UQ/h7xvqPq/Gc24PnR18fzVrp8I57d
mehj7ebk5VdPnp+d3GJOSP189eTsaXyk/JV7l98j4SAZgRxtf7x155PR+O6jz36Pw9/1Wz/+e/5u
v//vbsfQAxobws8M9v7xLXp/785/395ED4nO1wx5fsTeH4LnRva+eYY8rpZUBFb/j/jfm8XAvfEj
4/b/ljF1F9B/jx5PhAkp1nu/+y3n+kdZp/93jWmjJ/M11TG++VEG6puZn593PPejoOyHMQU/79jq
GwrKfpSB+tmcwZ93XPkjZffDmIKfd2z1DSm7bmCoPPmjBNT74XkrVf71I/Sf6wTU7XJA4RB+lIC6
mW1+xN5GWw1/683C5rnj/m364cmr45Pf6/SN9H4Us4LISn355vjN2ZcvtDGT6fHvapJcMISmxc0K
MAD4IyP6/5Yx/SwkP360FvD1VTH191mURr/HUY+2P3I9boPnz7Ju/pHrcWPnP3I9/r/L3sN0v52z
0fEgNrgbL8/Evfh9fw/q5Xf93u/97vvf+2Lx/e89L7+/Fe3iZ37f34P5h178kTfx/5YxfUs8vY26
7/d4/OWbb5++ogn7PX5XzOHtOP3GrsHmqobOVO/8Hh1Gk/TPl198QS6w+rLb23fcZ0fMaTfjsv29
7Zul7me2v0FgRoYVURnf9nZEkDD+H2VDf8hjeq8xff1s6GbButNLacEtefHm9VdPXp++CRTw7/v9
r6vW8b9eJ0+/PIHzs1HHdyKE/x9L4Y+s2f+PJPX/1dbsJn3wrY6wiqv85vjVm9Pnp+DgN8efM5va
j794+eb36Xz3mAf5+58+f3r68s230dRvJcxKn/l//oh3f+7H9K2O0r05PXf85s2rH83f/1vGdAvd
w+qBFqsoWvzspozD77EpXYeZ7yzdfxy0ec+l+8e/8FbR84+Wd78xbvn/qQQMz/J7L++GPB7N0MQa
2vTMBwjDrVI0PxKGb4xxfiQMX0cYPuq/Fbx2C1sU8yEF+F34iNsx1xOGa9t6l/yX70uqmxu+qBGm
AxlxWwVS11O97ULqlsFIUvUnT4/fHIuL//3f9/t9J39Y9m8W/Tuc296yUeX/b0PiHwUeP1801Y8C
j/9vz9+PAo8f+Vq35Jb/n0rAz7Kv9aPA40fC8P+RMf3sC8PP08DjR1L3DXHoj6SuIz/CCghZNZb8
fb/Hf/2+37tjvuBY9vu3jmRvxNeGgQAuaAF6Pwj8/+e66M8/7rwpRNj6uVwXZRl52k0n3FVl95Q+
+fz0KSu73/dtkGDYdvZgSP5uskadrtViRKyal2IKAiQfiW+FI+tET/9/Txj9SFf8SFf8rOuKzagx
+r/vD34mUADO1P4/AQAA//8=
</code></pre>

<p>The options to set is <code>RegexOptions.ExplicitCapture</code>. The capture group you are looking for is <code>ELEMENTNAME</code>. If the capture group <code>ERROR</code> is not empty then there was a parsing error and the Regex stopped.</p>

<p>If you have problems reconverting it to a human-readable regex, this should help:</p>

<pre class="lang-csharp prettyprint-override"><code>static string FromBase64(string str)
{
    byte[] byteArray = Convert.FromBase64String(str);

    using (var msIn = new MemoryStream(byteArray))
    using (var msOut = new MemoryStream()) {
        using (var ds = new DeflateStream(msIn, CompressionMode.Decompress)) {
            ds.CopyTo(msOut);
        }

        return Encoding.UTF8.GetString(msOut.ToArray());
    }
}
</code></pre>

<p>If you are unsure, no, I'm NOT kidding (but perhaps I'm lying). It WILL work. I've built tons of unit tests to test it, and I have even used (part of) the <a href="http://www.w3.org/XML/Test/" rel="noreferrer">conformance tests</a>. It's a tokenizer, not a full-blown parser, so it will only split the XML into its component tokens. It won't parse/integrate DTDs.</p>

<p>Oh... if you want the source code of the regex, with some auxiliary methods:</p>

<p><a href="http://pastebin.com/hzYazFVb" rel="noreferrer">regex to tokenize an xml</a> or <a href="http://pastebin.com/HUmPzP5M" rel="noreferrer">the full plain regex</a> </p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2011-03-08T13:30:46"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/5233151"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/5233151/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-5233151" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/5233151/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2017-10-18 07:26:13Z" class="relativetime">Oct 18 '17 at 7:26</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Mar 8 &#39;11 at 13:30. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-5233151" href="/posts/5233151/revisions" title="show revision history for this post">
        11 revs, 9 users 71%<br><a href="/users/613130">xanatos</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-5233151" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="5233151" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="27"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-5890952" class="comment js-comment " data-comment-id="5890952">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">68</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Good Lord, it&#39;s massive. My biggest question is why? You realize that all modern languages have XML parsers, right? You can do all that in like 3 lines and be sure it&#39;ll work. Furthermore, do you also realize that pure regex is <b>provably</b> unable to do certain things? Unless you&#39;ve created a hybrid regex/imperative code parser, but it doesn&#39;t look like you have. Can you compress random data as well?</span>
                
&ndash;&nbsp;<a href="/users/399649/justin-morgan"
                       title="25,998 reputation"
                       class="comment-user">Justin Morgan</a>
                <span class="comment-date" dir="ltr"><span title="2011-03-08 15:23:45Z, License: CC BY-SA 2.5" class="relativetime-clean">Mar 8 '11 at 15:23</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-5891077" class="comment js-comment " data-comment-id="5891077">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">113</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Justin I don&#39;t need a reason. It could be done (and it wasn&#39;t illegal/immoral), so I have done it. There are no limitations to the mind except those we acknowledge (Napoleon Hill)... Modern languages can parse XML? Really? And I thought that THAT was illegal! :-)</span>
                
&ndash;&nbsp;<a href="/users/613130/xanatos"
                       title="95,388 reputation"
                       class="comment-user">xanatos</a>
                <span class="comment-date" dir="ltr"><span title="2011-03-08 15:31:34Z, License: CC BY-SA 2.5" class="relativetime-clean">Mar 8 '11 at 15:31</span></span>
            </div>
        </div>
    </li>
    <li id="comment-5893435" class="comment js-comment " data-comment-id="5893435">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">76</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Sir, I&#39;m convinced. I&#39;m going to use this code as part of the kernel for my perpetual-motion machine--can you believe those fools at the patent office keep rejecting my application? Well, I&#39;ll show them. I&#39;ll show them all!</span>
                
&ndash;&nbsp;<a href="/users/399649/justin-morgan"
                       title="25,998 reputation"
                       class="comment-user">Justin Morgan</a>
                <span class="comment-date" dir="ltr"><span title="2011-03-08 17:55:54Z, License: CC BY-SA 2.5" class="relativetime-clean">Mar 8 '11 at 17:55</span></span>
            </div>
        </div>
    </li>
    <li id="comment-5907706" class="comment js-comment " data-comment-id="5907706">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">31</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Justin So an Xml Parser is by definition bug free, while a Regex isn&#39;t? Because if an Xml Parser isn&#39;t bug free by definition there could be an xml that make it crash and we are back to step 0. Let say this: both the Xml Parser and this Regex try to be able to parse all the &quot;legal&quot; XML. They CAN parse some &quot;illegal&quot; XML. Bugs could crash both of them. C# XmlReader is surely more tested than this Regex.</span>
                
&ndash;&nbsp;<a href="/users/613130/xanatos"
                       title="95,388 reputation"
                       class="comment-user">xanatos</a>
                <span class="comment-date" dir="ltr"><span title="2011-03-09 15:08:36Z, License: CC BY-SA 2.5" class="relativetime-clean">Mar 9 '11 at 15:08</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-11735313" class="comment js-comment " data-comment-id="11735313">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">31</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">No, nothing is bug free: 1) All programs contain at least one bug. 2) All programs contain at least one line of unnecessary source code. 3) By #1 and #2 and using logical induction, it&#39;s a simple matter to prove that any program can be reduced to a single line of code with a bug. (from Learning Perl)</span>
                
&ndash;&nbsp;<a href="/users/244811/scott-weaver"
                       title="5,729 reputation"
                       class="comment-user">Scott Weaver</a>
                <span class="comment-date" dir="ltr"><span title="2012-02-16 00:53:34Z, License: CC BY-SA 3.0" class="relativetime-clean">Feb 16 '12 at 0:53</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-5233151" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>27</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="2263520"></a>
<div id="answer-2263520" class="answer" data-answerid="2263520"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="2263520">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="300">300</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2263520/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>In shell, you can parse <a href="https://en.wikipedia.org/wiki/HTML" rel="noreferrer">HTML</a> using <a href="https://en.wikipedia.org/wiki/Sed" rel="noreferrer">sed</a>:</p>

<ol>
<li><a href="http://sed.sourceforge.net/grabbag/scripts/turing.sed" rel="noreferrer">Turing.sed</a></li>
<li>Write HTML parser (homework)</li>
<li>???</li>
<li>Profit!</li>
</ol>

<hr>

<p>Related (why you shouldn't use regex match):</p>

<ul>
<li><a href="https://blog.codinghorror.com/if-you-like-regular-expressions-so-much-why-dont-you-marry-them/" rel="noreferrer">If You Like Regular Expressions So Much, Why Don't You Marry Them?</a></li>
<li><a href="https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/" rel="noreferrer">Regular Expressions: Now You Have Two Problems</a></li>
<li><a href="http://danlec.com/blog/hacking-stackoverflow-com-s-html-sanitizer" rel="noreferrer">Hacking stackoverflow.com's HTML sanitizer</a></li>
</ul>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2010-02-15T00:55:24"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/2263520"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 4.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/2263520/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-2263520" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/2263520/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2019-04-23 16:44:36Z" class="relativetime">Apr 23 '19 at 16:44</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Feb 15 &#39;10 at 0:55. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2263520" href="/posts/2263520/revisions" title="show revision history for this post">
        10 revs, 7 users 43%<br><a href="/users/55075">kenorb</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-2263520" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="2263520" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="2"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-54010279" class="comment js-comment " data-comment-id="54010279">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I’m afraid you did not get the joke, @kenorb. Please, read the question and the accepted answer once more. This is not about HTML parsing tools in general, nor about HTML parsing shell tools, it’s about parsing HTML via regexes.</span>
                
&ndash;&nbsp;<a href="/users/2157640/palec"
                       title="9,346 reputation"
                       class="comment-user">Palec</a>
                <span class="comment-date" dir="ltr"><span title="2015-10-13 08:12:01Z, License: CC BY-SA 3.0" class="relativetime-clean">Oct 13 '15 at 8:12</span></span>
            </div>
        </div>
    </li>
    <li id="comment-73090810" class="comment js-comment " data-comment-id="73090810">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">No, @Abdul. It is completely, provably (in the mathematical sense) impossible.</span>
                
&ndash;&nbsp;<a href="/users/2157640/palec"
                       title="9,346 reputation"
                       class="comment-user">Palec</a>
                <span class="comment-date" dir="ltr"><span title="2017-03-24 13:24:19Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 24 '17 at 13:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-73093275" class="comment js-comment " data-comment-id="73093275">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Yes, that answer summarizes it well, @Abdul. Note that, however, regex implementations are not really <i>regular</i> expressions in the mathematical sense -- they have constructs that make them stronger, often Turing-complete (equivalent to Type 0 grammars). The argument breaks with this fact, but is still somewhat valid in the sense that regexes were never meant to be capable of doing such a job, though.</span>
                
&ndash;&nbsp;<a href="/users/2157640/palec"
                       title="9,346 reputation"
                       class="comment-user">Palec</a>
                <span class="comment-date" dir="ltr"><span title="2017-03-24 14:24:35Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 24 '17 at 14:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-73093363" class="comment js-comment " data-comment-id="73093363">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">And by the way, the joke I referred to was the content of this answer before kenorb&#39;s (radical) edits, specifically revision 4, @Abdul.</span>
                
&ndash;&nbsp;<a href="/users/2157640/palec"
                       title="9,346 reputation"
                       class="comment-user">Palec</a>
                <span class="comment-date" dir="ltr"><span title="2017-03-24 14:26:48Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 24 '17 at 14:26</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-86127667" class="comment js-comment " data-comment-id="86127667">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">The funny thing is that OP never asked to parse html using regex. He asked to match text (which happens to be HTML) using regex. Which is perfectly reasonable.</span>
                
&ndash;&nbsp;<a href="/users/11906/paralife"
                       title="5,570 reputation"
                       class="comment-user">Paralife</a>
                <span class="comment-date" dir="ltr"><span title="2018-03-29 15:29:49Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 29 '18 at 15:29</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-2263520" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>2</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="7564061"></a>
<div id="answer-7564061" class="answer" data-answerid="7564061"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="7564061">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="274">274</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/7564061/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>I agree that the right tool to parse XML and <em>especially HTML</em> is a parser and not a regular expression engine. However, like others have pointed out, sometimes using a regex is quicker, easier, and gets the job done if you know the data format.</p>

<p>Microsoft actually has a section of <a href="https://docs.microsoft.com/dotnet/standard/base-types/best-practices" rel="nofollow noreferrer">Best Practices for Regular Expressions in the .NET Framework</a> and specifically talks about <a href="https://docs.microsoft.com/dotnet/standard/base-types/best-practices#consider-the-input-source" rel="nofollow noreferrer">Consider[ing] the Input Source</a>.</p>

<p>Regular Expressions do have limitations, but have you considered the following?</p>

<p>The .NET framework is unique when it comes to regular expressions in that it supports <a href="https://docs.microsoft.com/dotnet/standard/base-types/grouping-constructs-in-regular-expressions#balancing_group_definition" rel="nofollow noreferrer">Balancing Group Definitions</a>.</p>

<ul>
<li>See <a href="https://weblogs.asp.net/whaggard/377025" rel="nofollow noreferrer">Matching Balanced Constructs with .NET Regular Expressions</a></li>
<li>See <a href="https://docs.microsoft.com/archive/blogs/bclteam/net-regular-expressions-regex-and-balanced-matching-ryan-byington" rel="nofollow noreferrer">.NET Regular Expressions: Regex and Balanced Matching</a></li>
<li>See Microsoft's docs on <a href="https://docs.microsoft.com/dotnet/standard/base-types/grouping-constructs-in-regular-expressions#balancing_group_definition" rel="nofollow noreferrer">Balancing Group Definitions</a></li>
</ul>

<p>For this reason, I believe you CAN parse XML using regular expressions. Note however, that it <strong>must be valid XML</strong> (<em>browsers are very forgiving of HTML and allow bad XML syntax inside HTML</em>). This is possible since the "Balancing Group Definition" will allow the regular expression engine to act as a PDA.</p>

<p>Quote from article 1 cited above:</p>

<blockquote>
  <p><strong>.NET Regular Expression Engine</strong></p>
  
  <p>As described above properly balanced constructs cannot be described by
  a regular expression. However, the .NET regular expression engine
  provides a few constructs that allow balanced constructs to be
  recognized. </p>
  
  <ul>
  <li><code>(?&lt;group&gt;)</code> - pushes the captured result on the capture stack with
  the name group.</li>
  <li><code>(?&lt;-group&gt;)</code> - pops the top most capture with the name group off the
  capture stack.</li>
  <li><code>(?(group)yes|no)</code> - matches the yes part if there exists a group
  with the name group otherwise matches no part.</li>
  </ul>
  
  <p>These constructs allow for a .NET regular expression to emulate a
  restricted PDA by essentially allowing simple versions of the stack
  operations: push, pop and empty. The simple operations are pretty much
  equivalent to increment, decrement and compare to zero respectively.
  This allows for the .NET regular expression engine to recognize a
  subset of the context-free languages, in particular the ones that only
  require a simple counter. This in turn allows for the non-traditional
  .NET regular expressions to recognize individual properly balanced
  constructs.</p>
</blockquote>

<p>Consider the following regular expression:</p>

<pre class="lang-none prettyprint-override"><code>(?=&lt;ul\s+id="matchMe"\s+type="square"\s*&gt;)
(?&gt;
   &lt;!-- .*? --&gt;                  |
   &lt;[^&gt;]*/&gt;                      |
   (?&lt;opentag&gt;&lt;(?!/)[^&gt;]*[^/]&gt;)  |
   (?&lt;-opentag&gt;&lt;/[^&gt;]*[^/]&gt;)     |
   [^&lt;&gt;]*
)*
(?(opentag)(?!))
</code></pre>

<p>Use the flags:</p>

<ul>
<li>Singleline</li>
<li>IgnorePatternWhitespace (not necessary if you collapse regex and remove all whitespace)</li>
<li>IgnoreCase (not necessary)</li>
</ul>

<h2>Regular Expression Explained (inline)</h2>

<pre class="lang-none prettyprint-override"><code>(?=&lt;ul\s+id="matchMe"\s+type="square"\s*&gt;) # match start with &lt;ul id="matchMe"...
(?&gt;                                        # atomic group / don't backtrack (faster)
   &lt;!-- .*? --&gt;                 |          # match xml / html comment
   &lt;[^&gt;]*/&gt;                     |          # self closing tag
   (?&lt;opentag&gt;&lt;(?!/)[^&gt;]*[^/]&gt;) |          # push opening xml tag
   (?&lt;-opentag&gt;&lt;/[^&gt;]*[^/]&gt;)    |          # pop closing xml tag
   [^&lt;&gt;]*                                  # something between tags
)*                                         # match as many xml tags as possible
(?(opentag)(?!))                           # ensure no 'opentag' groups are on stack
</code></pre>

<p>You can try this at <a href="http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx" rel="nofollow noreferrer">A Better .NET Regular Expression Tester</a>.</p>

<p>I used the sample source of:</p>

<pre><code>&lt;html&gt;
&lt;body&gt;
&lt;div&gt;
   &lt;br /&gt;
   &lt;ul id="matchMe" type="square"&gt;
      &lt;li&gt;stuff...&lt;/li&gt;
      &lt;li&gt;more stuff&lt;/li&gt;
      &lt;li&gt;
          &lt;div&gt;
               &lt;span&gt;still more&lt;/span&gt;
               &lt;ul&gt;
                    &lt;li&gt;Another &amp;gt;ul&amp;lt;, oh my!&lt;/li&gt;
                    &lt;li&gt;...&lt;/li&gt;
               &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/li&gt;
   &lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This found the match:</p>

<pre><code>   &lt;ul id="matchMe" type="square"&gt;
      &lt;li&gt;stuff...&lt;/li&gt;
      &lt;li&gt;more stuff&lt;/li&gt;
      &lt;li&gt;
          &lt;div&gt;
               &lt;span&gt;still more&lt;/span&gt;
               &lt;ul&gt;
                    &lt;li&gt;Another &amp;gt;ul&amp;lt;, oh my!&lt;/li&gt;
                    &lt;li&gt;...&lt;/li&gt;
               &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/li&gt;
   &lt;/ul&gt;
</code></pre>

<p>although it actually came out like this:</p>

<pre><code>&lt;ul id="matchMe" type="square"&gt;           &lt;li&gt;stuff...&lt;/li&gt;           &lt;li&gt;more stuff&lt;/li&gt;           &lt;li&gt;               &lt;div&gt;                    &lt;span&gt;still more&lt;/span&gt;                    &lt;ul&gt;                         &lt;li&gt;Another &amp;gt;ul&amp;lt;, oh my!&lt;/li&gt;                         &lt;li&gt;...&lt;/li&gt;                    &lt;/ul&gt;               &lt;/div&gt;           &lt;/li&gt;        &lt;/ul&gt;
</code></pre>

<p>Lastly, I really enjoyed Jeff Atwood's article:  <a href="https://blog.codinghorror.com/parsing-html-the-cthulhu-way/" rel="nofollow noreferrer">Parsing Html The Cthulhu Way</a>. Funny enough, it cites the answer to this question that currently has over 4k votes.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2011-09-27T04:01:04"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/7564061"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 4.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/7564061/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-7564061" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info user-hover">
    <div class="user-action-time">
        <a href="/posts/7564061/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2020-02-23 04:43:47Z" class="relativetime">Feb 23 at 4:43</span></a>
    </div>
    <div class="user-gravatar32">
        <a href="/users/4415734/callum-watkins"><div class="gravatar-wrapper-32"><img src="https://i.stack.imgur.com/x6QKy.png?s=32&amp;g=1" alt="" width="32" height="32" class="bar-sm"></div></a>
    </div>
    <div class="user-details">
        <a href="/users/4415734/callum-watkins">Callum Watkins</a>
        <div class="-flair">
            <span class="reputation-score" title="reputation score " dir="ltr">2,133</span><span title="2 gold badges" aria-hidden="true"><span class="badge1"></span><span class="badgecount">2</span></span><span class="v-visible-sr">2 gold badges</span><span title="22 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">22</span></span><span class="v-visible-sr">22 silver badges</span><span title="39 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">39</span></span><span class="v-visible-sr">39 bronze badges</span>
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info user-hover">
    <div class="user-action-time">
        answered <span title="2011-09-27 04:01:04Z" class="relativetime">Sep 27 '11 at 4:01</span>
    </div>
    <div class="user-gravatar32">
        <a href="/users/590956/sam"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/efa6d867fd2fc69944ae52b86e9b1687?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32" class="bar-sm"></div></a>
    </div>
    <div class="user-details" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <a href="/users/590956/sam">Sam</a><span class="d-none" itemprop="name">Sam</span>
        <div class="-flair">
            <span class="reputation-score" title="reputation score 25,406" dir="ltr">25.4k</span><span title="12 gold badges" aria-hidden="true"><span class="badge1"></span><span class="badgecount">12</span></span><span class="v-visible-sr">12 gold badges</span><span title="65 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">65</span></span><span class="v-visible-sr">65 silver badges</span><span title="97 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">97</span></span><span class="v-visible-sr">97 bronze badges</span>
        </div>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-7564061" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="7564061" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-11457016" class="comment js-comment " data-comment-id="11457016">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">18</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy"><code>System.Text</code> is not part of C#. It&#39;s part of .NET.</span>
                
&ndash;&nbsp;<a href="/users/76337/john-saunders"
                       title="155,818 reputation"
                       class="comment-user">John Saunders</a>
                <span class="comment-date" dir="ltr"><span title="2012-02-02 19:07:53Z, License: CC BY-SA 3.0" class="relativetime-clean">Feb 2 '12 at 19:07</span></span>
            </div>
        </div>
    </li>
    <li id="comment-14956273" class="comment js-comment " data-comment-id="14956273">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">8</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">In the first line of your regex (<code>(?=&lt;ul\s*id=&quot;matchMe&quot;\s*type=&quot;square&quot;\s*&gt;) # match start with &lt;ul id=&quot;matchMe&quot;...</code>), in between &quot;&lt;ul&quot; and &quot;id&quot; should be <code>\s+</code>, not <code>\s*</code>, unless you want it to match &lt;ulid=... ;)</span>
                
&ndash;&nbsp;<a href="/users/1344461/c0deh4cker"
                       title="3,526 reputation"
                       class="comment-user">C0deH4cker</a>
                <span class="comment-date" dir="ltr"><span title="2012-07-06 02:49:08Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 6 '12 at 2:49</span></span>
            </div>
        </div>
    </li>
    <li id="comment-14982109" class="comment js-comment " data-comment-id="14982109">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@C0deH4cker You are correct, the expression should have <code>\s+</code> instead of <code>\s*</code>.</span>
                
&ndash;&nbsp;<a href="/users/590956/sam"
                       title="25,406 reputation"
                       class="comment-user">Sam</a>
                <span class="comment-date" dir="ltr"><span title="2012-07-06 22:33:05Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 6 '12 at 22:33</span></span>
            </div>
        </div>
    </li>
    <li id="comment-28164133" class="comment js-comment " data-comment-id="28164133">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">4</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Not that I really understand it, but I think your regex fails on <code>&lt;img src=&quot;images&#47;pic.jpg&quot; &#47;&gt;</code></span>
                
&ndash;&nbsp;<a href="/users/1455622/scheintod"
                       title="7,033 reputation"
                       class="comment-user">Scheintod</a>
                <span class="comment-date" dir="ltr"><span title="2013-09-27 17:05:13Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 27 '13 at 17:05</span></span>
            </div>
        </div>
    </li>
    <li id="comment-28167413" class="comment js-comment " data-comment-id="28167413">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Scheintod Thank you for the comment.  I updated the code.  The previous expression failed for self closing tags that had a <code>&#47;</code> somewhere inside which failed for your <code>&lt;img src=&quot;images&#47;pic.jpg&quot; &#47;&gt;</code> html.</span>
                
&ndash;&nbsp;<a href="/users/590956/sam"
                       title="25,406 reputation"
                       class="comment-user">Sam</a>
                <span class="comment-date" dir="ltr"><span title="2013-09-27 19:00:25Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 27 '13 at 19:00</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-7564061" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1732595"></a>
<div id="answer-1732595" class="answer" data-answerid="1732595"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1732595">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="258">258</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732595/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>I suggest using <a href="http://querypath.org/" rel="noreferrer">QueryPath</a> for parsing XML and HTML in PHP.  It's basically much the same syntax as jQuery, only it's on the server side.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-13T23:44:50"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1732595"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1732595/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1732595" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732595/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2015-05-12 18:54:20Z" class="relativetime">May 12 '15 at 18:54</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732595" href="/posts/1732595/revisions" title="show revision history for this post">
        4 revs, 4 users 57%<br><a href="/users/9143">John Fiala</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1732595" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1732595" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-29262125" class="comment js-comment " data-comment-id="29262125">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">8</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Kyle—jQuery does not parse XML, it uses the client&#39;s built–in parser (if there is one). Therefore you do not need jQuery to do it, but as little as two lines of <a href="https://developer.mozilla.org/en-US/docs/Parsing_and_serializing_XML" rel="nofollow noreferrer">plain old JavaScript</a>. If there is no built–in parser, jQuery will not help.</span>
                
&ndash;&nbsp;<a href="/users/257182/robg"
                       title="113,775 reputation"
                       class="comment-user">RobG</a>
                <span class="comment-date" dir="ltr"><span title="2013-10-31 06:25:27Z, License: CC BY-SA 3.0" class="relativetime-clean">Oct 31 '13 at 6:25</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-40656661" class="comment js-comment " data-comment-id="40656661">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@RobG Actually jQuery uses the DOM, not the built-in parser.</span>
                
&ndash;&nbsp;<a href="/users/510036/qix-monica-was-mistreated"
                       title="11,281 reputation"
                       class="comment-user">Qix - MONICA WAS MISTREATED</a>
                <span class="comment-date" dir="ltr"><span title="2014-09-22 03:49:04Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 22 '14 at 3:49</span></span>
            </div>
        </div>
    </li>
    <li id="comment-40657671" class="comment js-comment " data-comment-id="40657671">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">11</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Qix—you&#39;d better tell the authors of the documentation then: &quot;<i>jQuery.parseXML uses the native parsing function of the browser…</i>&quot;. Source: <a href="http://api.jquery.com/jQuery.parseXML/" rel="nofollow noreferrer"><i>jQuery.parseXML()</i></a></span>
                
&ndash;&nbsp;<a href="/users/257182/robg"
                       title="113,775 reputation"
                       class="comment-user">RobG</a>
                <span class="comment-date" dir="ltr"><span title="2014-09-22 05:01:30Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 22 '14 at 5:01</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-60351141" class="comment js-comment " data-comment-id="60351141">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">6</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Having come here from the meme question (<a href="http://meta.stackexchange.com/questions/19478/the-many-memes-of-meta/19479#19479" title="the many memes of meta">meta.stackexchange.com/questions/19478/the-many-memes-of-meta/&hellip;</a>), I love that one of the answers is &#39;Use jQuery&#39;</span>
                
&ndash;&nbsp;<a href="/users/8681/jorn"
                       title="15,515 reputation"
                       class="comment-user">Jorn</a>
                <span class="comment-date" dir="ltr"><span title="2016-04-01 21:09:45Z, License: CC BY-SA 3.0" class="relativetime-clean">Apr 1 '16 at 21:09</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1732595" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="2146912"></a>
<div id="answer-2146912" class="answer" data-answerid="2146912"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="2146912">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="221">221</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2146912/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>While the answers that you can't parse HTML with regexes are correct, they don't apply here. The OP just wants to parse one HTML tag with regexes, and that is something that can be done with a regular expression.</p>

<p>The suggested regex is wrong, though:</p>

<pre><code>&lt;([a-z]+) *[^/]*?&gt;
</code></pre>

<p>If you add something to the regex, by backtracking it can be forced to match silly things like <code>&lt;a &gt;&gt;</code>, <code>[^/]</code> is too permissive. Also note that <code>&lt;space&gt;*[^/]*</code> is redundant, because the <code>[^/]*</code> can also match spaces.</p>

<p>My suggestion would be</p>

<pre><code>&lt;([a-z]+)[^&gt;]*(?&lt;!/)&gt;
</code></pre>

<p>Where <code>(?&lt;! ... )</code> is (in Perl regexes) the negative look-behind. It reads "a &lt;, then a word, then anything that's not a >, the last of which may not be a /, followed by >".</p>

<p>Note that this allows things like <code>&lt;a/ &gt;</code> (just like the original regex), so if you want something more restrictive, you need to build a regex to match attribute pairs separated by spaces.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2010-01-27T12:54:35"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/2146912"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/2146912/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-2146912" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/2146912/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title="2010-01-27 12:54:35Z" class="relativetime">Jan 27 '10 at 12:54</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jan 27 &#39;10 at 12:54. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2146912" href="/posts/2146912/revisions" title="show revision history for this post">
        moritz
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-2146912" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="2146912" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="1"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-16545748" class="comment js-comment " data-comment-id="16545748">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">29</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">+1 for noting that the question is not about parsing full (X)HTML, it&#39;s about matching (X)HTML open tags.</span>
                
&ndash;&nbsp;<a href="/users/423105/larsh"
                       title="24,446 reputation"
                       class="comment-user">LarsH</a>
                <span class="comment-date" dir="ltr"><span title="2012-09-08 02:26:22Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 8 '12 at 2:26</span></span>
            </div>
        </div>
    </li>
    <li id="comment-46771251" class="comment js-comment " data-comment-id="46771251">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">10</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Something else most of the answers seem to ignore, is that an HTML parser can very well use regular expressions in its implementation for parts of HTML, and I would be surprised if most parsers didn&#39;t do this.</span>
                
&ndash;&nbsp;<a href="/users/2543666/thayne"
                       title="5,432 reputation"
                       class="comment-user">Thayne</a>
                <span class="comment-date" dir="ltr"><span title="2015-03-26 19:15:04Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 26 '15 at 19:15</span></span>
            </div>
        </div>
    </li>
    <li id="comment-55471750" class="comment js-comment " data-comment-id="55471750">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Thayne Exactly. When parsing individual tags, a regular expression is the right tool for the job. It is quite ridiculous that one has to scroll halfway down the page to find a reasonable answer. The accepted answer is incorrect because it mixes up lexing and parsing.</span>
                
&ndash;&nbsp;<a href="/users/3476849/kasperd"
                       title="1,762 reputation"
                       class="comment-user">kasperd</a>
                <span class="comment-date" dir="ltr"><span title="2015-11-22 10:26:25Z, License: CC BY-SA 3.0" class="relativetime-clean">Nov 22 '15 at 10:26</span></span>
            </div>
        </div>
    </li>
    <li id="comment-61105461" class="comment js-comment " data-comment-id="61105461">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">The answer given here will fail when an attribute value contains a &#39;&gt;&#39; or &#39;/&#39; character.</span>
                
&ndash;&nbsp;<a href="/users/3829420/martin-l"
                       title="766 reputation"
                       class="comment-user">Martin L</a>
                <span class="comment-date" dir="ltr"><span title="2016-04-21 08:14:04Z, License: CC BY-SA 3.0" class="relativetime-clean">Apr 21 '16 at 8:14</span></span>
            </div>
        </div>
    </li>
    <li id="comment-77757983" class="comment js-comment " data-comment-id="77757983">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">This will work incorrectly on HTML containing comments or CData sections.  It will also not work correctly if a quoted attribute contains a <code>&gt;</code> character. I agree what OP suggest <i>can</i> be done with a regex, but the one presented here is far to simplistic.</span>
                
&ndash;&nbsp;<a href="/users/7488/jacquesb"
                       title="38,055 reputation"
                       class="comment-user">JacquesB</a>
                <span class="comment-date" dir="ltr"><span title="2017-07-30 10:14:41Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 30 '17 at 10:14</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-2146912" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>1</b> more comment</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1732395"></a>
<div id="answer-1732395" class="answer" data-answerid="1732395"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1732395">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="183">183</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732395/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>Try:</p>

<pre><code>&lt;([^\s]+)(\s[^&gt;]*?)?(?&lt;!/)&gt;
</code></pre>

<p>It is similar to yours, but the last <code>&gt;</code> must not be after a slash, and also accepts <code>h1</code>.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-13T22:50:48"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1732395"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1732395/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1732395" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732395/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2009-11-25 21:12:04Z" class="relativetime">Nov 25 '09 at 21:12</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732395" href="/posts/1732395/revisions" title="show revision history for this post">
        3 revs, 2 users 77%<br><a href="/users/7586">Kobi</a>

        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1732395" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1732395" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="3"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-1612303" class="comment js-comment " data-comment-id="1612303">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">107</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">&lt;a href=&quot;foo&quot; title=&quot;5&gt;3&quot;&gt; Oops &lt;/a&gt;</span>
                
&ndash;&nbsp;<a href="/users/31582/gareth"
                       title="106,420 reputation"
                       class="comment-user">Gareth</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-13 23:11:39Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 13 '09 at 23:11</span></span>
            </div>
        </div>
    </li>
    <li id="comment-1612331" class="comment js-comment " data-comment-id="1612331">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">21</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">That is very true, and I did think about it, but I assumed the <code>&gt;</code> symbol is properly escaped to &amp;gt;.</span>
                
&ndash;&nbsp;<a href="/users/7586/kobi"
                       title="119,199 reputation"
                       class="comment-user">Kobi</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-13 23:16:59Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 13 '09 at 23:16</span></span>
            </div>
        </div>
    </li>
    <li id="comment-1612577" class="comment js-comment " data-comment-id="1612577">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">65</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy"><code>&gt;</code> is valid in an attribute value. Indeed, in the ‘canonical XML’ serialisation you must not use <code>&amp;gt;</code>. (Which isn&#39;t entirely relevant, except to emphasise that <code>&gt;</code> in an attribute value is not at all an unusual thing.)</span>
                
&ndash;&nbsp;<a href="/users/18936/bobince"
                       title="478,501 reputation"
                       class="comment-user">bobince</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-14 00:15:33Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 14 '09 at 0:15</span></span>
            </div>
        </div>
    </li>
    <li id="comment-6710778" class="comment js-comment " data-comment-id="6710778">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">5</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Kobi: what does the exlamation mark (the one you placed tpward the end) mean in a regexp?</span>
                
&ndash;&nbsp;<a href="/users/260080/marco-demaio"
                       title="29,513 reputation"
                       class="comment-user">Marco Demaio</a>
                <span class="comment-date" dir="ltr"><span title="2011-04-30 17:16:11Z, License: CC BY-SA 3.0" class="relativetime-clean">Apr 30 '11 at 17:16</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-6710897" class="comment js-comment " data-comment-id="6710897">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">6</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@bobince: are u sure? I don&#39;t understand anymore, so is this valid HTML too: <code>&lt;div title=&quot;this tag is a &lt;div&gt;&lt;&#47;div&gt;&quot;&gt;hello&lt;&#47;div&gt;</code></span>
                
&ndash;&nbsp;<a href="/users/260080/marco-demaio"
                       title="29,513 reputation"
                       class="comment-user">Marco Demaio</a>
                <span class="comment-date" dir="ltr"><span title="2011-04-30 17:31:15Z, License: CC BY-SA 3.0" class="relativetime-clean">Apr 30 '11 at 17:31</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1732395" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>3</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="10633717"></a>
<div id="answer-10633717" class="answer" data-answerid="10633717"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="10633717">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="179">179</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10633717/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>Sun Tzu, an ancient Chinese strategist, general, and philosopher, said:</p>

<blockquote>
  <p>It is said that if you know your enemies and know yourself, you can win a hundred battles without a single loss.
  If you only know yourself, but not your opponent, you may win or may lose.
  If you know neither yourself nor your enemy, you will always endanger yourself.</p>
</blockquote>

<p>In this case your enemy is HTML and you are either yourself or regex.  You might even be Perl with irregular regex. Know HTML.  Know yourself.</p>

<p>I have composed a haiku describing the nature of HTML.</p>

<pre><code>HTML has
complexity exceeding
regular language.
</code></pre>

<p>I have also composed a haiku describing the nature of regex in Perl.</p>

<pre><code>The regex you seek
is defined within the phrase
&lt;([a-zA-Z]+)(?:[^&gt;]*[^/]*)?&gt;
</code></pre>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2012-05-17T10:13:03"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/10633717"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/10633717/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-10633717" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10633717/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2013-10-05 04:52:53Z" class="relativetime">Oct 5 '13 at 4:52</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of May 17 &#39;12 at 10:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10633717" href="/posts/10633717/revisions" title="show revision history for this post">
        2 revs, 2 users 98%<br><a href="/users/863553">cytinus</a>

        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-10633717" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="10633717" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-10633717" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1737662"></a>
<div id="answer-1737662" class="answer" data-answerid="1737662"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1737662">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="153">153</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1737662/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<pre><code>&lt;?php
$selfClosing = explode(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed');

$html = '
&lt;p&gt;&lt;a href="#"&gt;foo&lt;/a&gt;&lt;/p&gt;
&lt;hr/&gt;
&lt;br/&gt;
&lt;div&gt;name&lt;/div&gt;';

$dom = new DOMDocument();
$dom-&gt;loadHTML($html);
$els = $dom-&gt;getElementsByTagName('*');
foreach ( $els as $el ) {
    $nodeName = strtolower($el-&gt;nodeName);
    if ( !in_array( $nodeName, $selfClosing ) ) {
        var_dump( $nodeName );
    }
}
</code></pre>

<p>Output:</p>

<pre><code>string(4) "html"
string(4) "body"
string(1) "p"
string(1) "a"
string(3) "div"
</code></pre>

<p>Basically just define the element node names that are self closing, load the whole html string into a DOM library, grab all elements, loop through and filter out ones which aren't self closing and operate on them.</p>

<p>I'm sure you already know by now that you shouldn't use regex for this purpose.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-15T14:37:06"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1737662"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1737662/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1737662" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1737662/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2009-11-15 14:44:04Z" class="relativetime">Nov 15 '09 at 14:44</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1737662" href="/posts/1737662/revisions" title="show revision history for this post">
        2 revs<br><a href="/users/145190">meder</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1737662" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1737662" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-1618096" class="comment js-comment " data-comment-id="1618096">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">If you&#39;re dealing with real XHTML then append getElementsByTagName with <code>NS</code> and specify the namespace.</span>
                
&ndash;&nbsp;<a href="/users/145190/meder-omuraliev"
                       title="163,456 reputation"
                       class="comment-user">meder omuraliev</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-15 14:39:44Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 15 '09 at 14:39</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1737662" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1745488"></a>
<div id="answer-1745488" class="answer" data-answerid="1745488"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1745488">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="148">148</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1745488/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>I don't know your exact need for this, but if you are also using .NET, couldn't you use <a href="http://www.codeplex.com/htmlagilitypack" rel="noreferrer">Html Agility Pack</a>?</p>

<p>Excerpt:</p>

<blockquote>
  <p><em>It is a .NET code library that allows
  you to parse "out of the web" HTML
  files. The parser is very tolerant
  with "real world" malformed HTML.</em></p>
</blockquote>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-16T23:15:03"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1745488"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1745488/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1745488" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/1745488/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title="2009-11-16 23:15:03Z" class="relativetime">Nov 16 '09 at 23:15</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1745488" href="/posts/1745488/revisions" title="show revision history for this post">
        GONeale
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1745488" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="1745488" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1745488" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1732382"></a>
<div id="answer-1732382" class="answer" data-answerid="1732382"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1732382">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="137">137</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732382/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>You want the first <code>&gt;</code> not preceded by a <code>/</code>.  Look <a href="http://www.regular-expressions.info/lookaround.html" rel="noreferrer">here</a> for details on how to do that.  It's referred to as negative lookbehind.</p>

<p>However, a naïve implementation of that will end up matching <code>&lt;bar/&gt;&lt;/foo&gt;</code> in this example document</p>

<pre><code>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;
</code></pre>

<p>Can you provide a little more information on the problem you're trying to solve?  Are you iterating through tags programatically?</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-13T22:47:17"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1732382"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1732382/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1732382" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732382/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2012-03-19 15:04:25Z" class="relativetime">Mar 19 '12 at 15:04</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732382" href="/posts/1732382/revisions" title="show revision history for this post">
        2 revs, 2 users 89%<br><a href="/users/85306">Jherico</a>

        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1732382" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1732382" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-1612260" class="comment js-comment " data-comment-id="1612260">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Yep, I sure am. Determining all the tags that are currently open, then compare that against the closed tags in a separate array. RegEx hurts my brain.</span>
                
&ndash;&nbsp;<a href="/users/142233/jeff"
                       title="5,303 reputation"
                       class="comment-user owner">Jeff</a>
                <span class="comment-date" dir="ltr"><span title="2009-11-13 23:04:54Z, License: CC BY-SA 2.5" class="relativetime-clean">Nov 13 '09 at 23:04</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1732382" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1736770"></a>
<div id="answer-1736770" class="answer" data-answerid="1736770"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1736770">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="122">122</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1736770/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>The W3C explains parsing in a pseudo regexp form:<br>
<a href="http://www.w3.org/TR/REC-xml-names/#ns-using" rel="noreferrer">W3C Link</a>  </p>

<p>Follow the var links for <code>QName</code>, <code>S</code>, and <code>Attribute</code> to get a clearer picture.<br>
Based on that you can create a pretty good regexp to handle things like stripping tags.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-15T06:18:15"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1736770"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1736770/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1736770" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1736770/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2014-05-16 14:43:57Z" class="relativetime">May 16 '14 at 14:43</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1736770" href="/posts/1736770/revisions" title="show revision history for this post">
        2 revs, 2 users 92%<br><a href="/users/166625">John-David Dalton</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1736770" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1736770" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-45231567" class="comment js-comment " data-comment-id="45231567">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">5</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">That&#39;s not a psuedo regexp form, that&#39;s an EBNF form, as specified here: <a href="http://www.w3.org/TR/REC-xml/#sec-notation" rel="nofollow noreferrer">XML spec, appendix 6</a></span>
                
&ndash;&nbsp;<a href="/users/2097355/rob-g"
                       title="64 reputation"
                       class="comment-user">Rob G</a>
                <span class="comment-date" dir="ltr"><span title="2015-02-11 10:34:58Z, License: CC BY-SA 3.0" class="relativetime-clean">Feb 11 '15 at 10:34</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1736770" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1744154"></a>
<div id="answer-1744154" class="answer" data-answerid="1744154"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1744154">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="106">106</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1744154/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>If you need this for PHP:</p>

<p>The <a href="http://www.php.net/manual/en/function.dom-import-simplexml.php" rel="noreferrer">PHP DOM</a> <a href="http://php.net/manual/en/class.domdocument.php" rel="noreferrer">functions</a> won't work properly unless it is properly formatted XML. No matter how much better their use is for the rest of mankind.</p>

<p><a href="http://simplehtmldom.sourceforge.net/" rel="noreferrer">simplehtmldom</a> is good, but I found it a bit buggy, and it is is quite memory heavy [Will crash on large pages.]</p>

<p>I have never used <a href="http://querypath.org/" rel="noreferrer">querypath</a>, so can't comment on its usefulness. </p>

<p>Another one to try is my <a href="http://github.com/siteroller/domparser" rel="noreferrer">DOMParser</a> which is very light on resources and I've been using happily for a while. Simple to learn &amp; powerful.</p>

<p>For Python and Java, similar links were posted.</p>

<p>For the downvoters - I only wrote my class when the XML parsers proved unable to withstand real use. Religious downvoting just prevents useful answers from being posted - keep things within perspective of the question, please.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-16T19:02:48"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1744154"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1744154/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1744154" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1744154/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2012-03-19 15:02:18Z" class="relativetime">Mar 19 '12 at 15:02</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1744154" href="/posts/1744154/revisions" title="show revision history for this post">
        4 revs, 2 users 98%<br><a href="/users/87520">SamGoody</a>

        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1744154" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="1744154" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1744154" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="6817767"></a>
<div id="answer-6817767" class="answer" data-answerid="6817767"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="6817767">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="95">95</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/6817767/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>Here's the solution:</p>

<pre><code>&lt;?php
// here's the pattern:
$pattern = '/&lt;(\w+)(\s+(\w+)\s*\=\s*(\'|")(.*?)\\4\s*)*\s*(\/&gt;|&gt;)/';

// a string to parse:
$string = 'Hello, try clicking &lt;a href="#paragraph"&gt;here&lt;/a&gt;
    &lt;br/&gt;and check out.&lt;hr /&gt;
    &lt;h2&gt;title&lt;/h2&gt;
    &lt;a name ="paragraph" rel= "I\'m an anchor"&gt;&lt;/a&gt;
    Fine, &lt;span title=\'highlight the "punch"\'&gt;thanks&lt;span&gt;.
    &lt;div class = "clear"&gt;&lt;/div&gt;
    &lt;br&gt;';

// let's get the occurrences:
preg_match_all($pattern, $string, $matches, PREG_PATTERN_ORDER);

// print the result:
print_r($matches[0]);
?&gt;
</code></pre>

<p>To test it deeply, I entered in the string auto-closing tags like:</p>

<ol>
<li>&lt;hr /&gt;</li>
<li>&lt;br/&gt;</li>
<li>&lt;br&gt;</li>
</ol>

<p>I also entered tags with:</p>

<ol>
<li>one attribute</li>
<li>more than one attribute</li>
<li>attributes which value is bound either into <strong>single quotes</strong> or into <strong>double quotes</strong></li>
<li>attributes containing single quotes when the delimiter is a double quote and vice versa</li>
<li>"unpretty" attributes with a space before the "=" symbol, after it and both before and after it.</li>
</ol>

<p>Should you find something which does not work in the proof of concept above, I am available in analyzing the code to improve my skills.</p>

<p><strong>&lt;EDIT&gt;</strong>
I forgot that the question from the user was to avoid the parsing of self-closing tags.
In this case the pattern is simpler, turning into this:</p>

<pre><code>$pattern = '/&lt;(\w+)(\s+(\w+)\s*\=\s*(\'|")(.*?)\\4\s*)*\s*&gt;/';
</code></pre>

<p>The user @ridgerunner noticed that the pattern does not allow <strong>unquoted attributes</strong> or <strong>attributes with no value</strong>. In this case a fine tuning brings us the following pattern:</p>

<pre><code>$pattern = '/&lt;(\w+)(\s+(\w+)(\s*\=\s*(\'|"|)(.*?)\\5\s*)?)*\s*&gt;/';
</code></pre>

<p><strong>&lt;/EDIT&gt;</strong></p>

<h1>Understanding the pattern</h1>

<p>If someone is interested in learning more about the pattern, I provide some line:</p>

<ol>
<li>the first sub-expression (\w+) matches the tag name</li>
<li>the second sub-expression contains the pattern of an attribute. It is composed by:

<ol>
<li>one or more whitespaces \s+</li>
<li>the name of the attribute (\w+)</li>
<li>zero or more whitespaces \s* (it is possible or not, leaving blanks here)</li>
<li>the "=" symbol</li>
<li>again, zero or more whitespaces</li>
<li>the delimiter of the attribute value, a single or double quote ('|"). In the pattern, the single quote is escaped because it coincides with the PHP string delimiter. This sub-expression is captured with the parentheses so it can be referenced again to parse the closure of the attribute, that's why it is very important.</li>
<li>the value of the attribute, matched by <em>almost</em> anything: (.*?); in this specific syntax, using the <strong>greedy match</strong> (the question mark after the asterisk) the RegExp engine enables a "look-ahead"-like operator, which matches anything but what follows this sub-expression</li>
<li>here comes the fun: the \4 part is a <strong>backreference operator</strong>, which refers to a sub-expression defined before in the pattern, in this case, I am referring to the fourth sub-expression, which is the first attribute delimiter found</li>
<li>zero or more whitespaces \s*</li>
<li>the attribute sub-expression ends here, with the specification of zero or more possible occurrences, given by the asterisk.</li>
</ol></li>
<li>Then, since a tag may end with a whitespace before the "&gt;" symbol, zero or more whitespaces are matched with the \s* subpattern.</li>
<li>The tag to match may end with a simple "&gt;" symbol, or a possible XHTML closure, which makes use of the slash before it: (/>|>). The slash is, of course, escaped since it coincides with the regular expression delimiter.</li>
</ol>

<p>Small tip: to better analyze this code it is necessary looking at the source code generated since I did not provide any HTML special characters escaping.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2011-07-25T14:35:59"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/6817767"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/6817767/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-6817767" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/6817767/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2017-10-18 07:33:46Z" class="relativetime">Oct 18 '17 at 7:33</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jul 25 &#39;11 at 14:35. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-6817767" href="/posts/6817767/revisions" title="show revision history for this post">
        6 revs, 2 users 96%<br><a href="/users/383764">Emanuele Del Grande</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-6817767" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="6817767" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-8098950" class="comment js-comment " data-comment-id="8098950">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">12</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Does not match valid tags having attributes with no value, i.e. <code>&lt;option selected&gt;</code>. Also does not match valid tags with unquoted attribute values, i.e. <code>&lt;p id=10&gt;</code>.</span>
                
&ndash;&nbsp;<a href="/users/433790/ridgerunner"
                       title="28,987 reputation"
                       class="comment-user">ridgerunner</a>
                <span class="comment-date" dir="ltr"><span title="2011-07-25 15:01:59Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 25 '11 at 15:01</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-8100663" class="comment js-comment " data-comment-id="8100663">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@ridgerunner: Thanks very much for your comment. In that case the pattern must change a bit: $pattern = &#39;/&lt;(\w+)(\s+(\w+)(\s*\=\s*(\&#39;|&quot;|)(.*?)\\5\s*)?)*\s*&gt;/&#39;; I tested it and works in case of non-quoted attributes or attributes with no value.</span>
                
&ndash;&nbsp;<a href="/users/383764/emanuele-del-grande"
                       title="4,056 reputation"
                       class="comment-user">Emanuele Del Grande</a>
                <span class="comment-date" dir="ltr"><span title="2011-07-25 16:41:46Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 25 '11 at 16:41</span></span>
                        <span title="this comment was edited 3 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-28400943" class="comment js-comment " data-comment-id="28400943">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">How about a space before the tag name: <code>&lt; a href=&quot;http:&#47;&#47;wtf.org&quot; &gt;</code> I&#39;m pretty sure it is legal, but you don&#39;t match it.</span>
                
&ndash;&nbsp;<a href="/users/1967396/floris"
                       title="42,480 reputation"
                       class="comment-user">Floris</a>
                <span class="comment-date" dir="ltr"><span title="2013-10-05 04:58:49Z, License: CC BY-SA 3.0" class="relativetime-clean">Oct 5 '13 at 4:58</span></span>
            </div>
        </div>
    </li>
    <li id="comment-28430952" class="comment js-comment " data-comment-id="28430952">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">7</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">NO sorry, whitespaces before a tagname are illegal. Beyond being &quot;pretty sure&quot; why don&#39;t you provide some evidences of your objection? Here are mine, <a href="http://www.w3.org/TR/xml11/#sec-starttags" rel="nofollow noreferrer">w3.org/TR/xml11/#sec-starttags</a> referred to XML 1.1, and you can find the same for HTML 4, 5 and XHTML, as a W3C validation would also warn if you make a test. As a lot of other blah-blah-poets around here, I did not still receive any intelligent argumentation, apart some hundred of minus to my answers, to demonstrate where my code fails according to the <i>rules of contract</i> specified in the question. I would only welcome them.</span>
                
&ndash;&nbsp;<a href="/users/383764/emanuele-del-grande"
                       title="4,056 reputation"
                       class="comment-user">Emanuele Del Grande</a>
                <span class="comment-date" dir="ltr"><span title="2013-10-06 18:03:45Z, License: CC BY-SA 3.0" class="relativetime-clean">Oct 6 '13 at 18:03</span></span>
            </div>
        </div>
    </li>
    <li id="comment-28431068" class="comment js-comment " data-comment-id="28431068">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@ridgerunner of course your comment was intelligent and welcome.</span>
                
&ndash;&nbsp;<a href="/users/383764/emanuele-del-grande"
                       title="4,056 reputation"
                       class="comment-user">Emanuele Del Grande</a>
                <span class="comment-date" dir="ltr"><span title="2013-10-06 18:09:52Z, License: CC BY-SA 3.0" class="relativetime-clean">Oct 6 '13 at 18:09</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-6817767" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1756533"></a>
<div id="answer-1756533" class="answer" data-answerid="1756533"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1756533">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="91">91</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1756533/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>Whenever I need to quickly extract something from an HTML document, I use Tidy to convert it to XML and then use XPath or XSLT to get what I need.
In your case, something like this: </p>

<pre><code>//p/a[@href='foo']
</code></pre>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-18T14:50:26"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1756533"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1756533/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1756533" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1756533/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2014-04-04 08:11:06Z" class="relativetime">Apr 4 '14 at 8:11</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1756533" href="/posts/1756533/revisions" title="show revision history for this post">
        2 revs, 2 users 67%<br><a href="/users/1438393">Amal Murali</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1756533" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="1756533" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1756533" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1744002"></a>
<div id="answer-1744002" class="answer" data-answerid="1744002"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1744002">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="89">89</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1744002/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>I used a open source tool called <a href="http://htmlparser.sourceforge.net/">HTMLParser</a> before. It's designed to parse HTML in various ways and serves the purpose quite well. It can parse HTML as different treenode and you can easily use its API to get attributes out of the node. Check it out and see if this can help you.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-16T18:34:50"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1744002"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1744002/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1744002" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/1744002/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title="2009-11-16 18:34:50Z" class="relativetime">Nov 16 '09 at 18:34</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1744002" href="/posts/1744002/revisions" title="show revision history for this post">
        wen
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1744002" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="1744002" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1744002" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="6653839"></a>
<div id="answer-6653839" class="answer" data-answerid="6653839"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="6653839">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="84">84</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/6653839/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>I like to parse HTML with regular expressions. I don't attempt to parse idiot HTML that is deliberately broken. This code is my main parser (Perl edition):</p>

<pre><code>$_ = join "",&lt;STDIN&gt;; tr/\n\r \t/ /s; s/&lt;/\n&lt;/g; s/&gt;/&gt;\n/g; s/\n ?\n/\n/g;
s/^ ?\n//s; s/ $//s; print
</code></pre>

<p>It's called htmlsplit, splits the HTML into lines, with one tag or chunk of text on each line.  The lines can then be processed further with other text tools and scripts, such as <a href="http://en.wikipedia.org/wiki/Grep" rel="noreferrer">grep</a>, <a href="http://en.wikipedia.org/wiki/Sed" rel="noreferrer">sed</a>, Perl, etc. I'm not even joking :) Enjoy.</p>

<p>It is simple enough to rejig my slurp-everything-first Perl script into a nice streaming thing, if you wish to process enormous web pages. But it's not really necessary.</p>

<p>I bet I will get downvoted for this.</p>

<p><a href="http://sam.nipl.net/code/nipl-tools/bin/htmlsplit" rel="noreferrer">HTML Split</a></p>

<hr/>

<p>Against my expectation this got some upvotes, so I'll suggest some better regular expressions:</p>

<pre><code>/(&lt;.*?&gt;|[^&lt;]+)\s*/g    # get tags and text
/(\w+)="(.*?)"/g       # get attibutes
</code></pre>

<p>They are good for XML / XHTML.</p>

<p>With minor variations, it can cope with messy HTML... or convert the HTML -> XHTML first.</p>

<hr/>

<p>The best way to write regular expressions is in the <a href="http://en.wikipedia.org/wiki/Lex_%28software%29" rel="noreferrer">Lex</a> / <a href="http://en.wikipedia.org/wiki/Yacc" rel="noreferrer">Yacc</a> style, not as opaque one-liners or commented multi-line monstrosities. I didn't do that here, yet; these ones barely need it.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2011-07-11T17:13:17"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/6653839"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/6653839/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-6653839" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/6653839/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2014-11-18 16:15:09Z" class="relativetime">Nov 18 '14 at 16:15</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jul 11 &#39;11 at 17:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-6653839" href="/posts/6653839/revisions" title="show revision history for this post">
        5 revs, 3 users 69%<br><a href="/users/218294">Sam Watkins</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-6653839" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="6653839" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="4"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-8124904" class="comment js-comment " data-comment-id="8124904">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">35</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">&quot;I don&#39;t attempt to parse idiot HTML that is deliberately broken.&quot;  How does your code know the difference?</span>
                
&ndash;&nbsp;<a href="/users/125389/kevin-panko"
                       title="7,433 reputation"
                       class="comment-user">Kevin Panko</a>
                <span class="comment-date" dir="ltr"><span title="2011-07-26 20:38:07Z, License: CC BY-SA 3.0" class="relativetime-clean">Jul 26 '11 at 20:38</span></span>
            </div>
        </div>
    </li>
    <li id="comment-12196452" class="comment js-comment " data-comment-id="12196452">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Well it doesn&#39;t matter much if the HTML is broken or not.  The thing will still split HTML into tags and text.  The only thing that could foul it up is if people include unescaped &lt; or &gt; characters in text or attributes.  In practise, my tiny HTML splitter works well. I don&#39;t need an enormous monstrosity chock full of heuristics.  Simple solutions are not for everyone...!</span>
                
&ndash;&nbsp;<a href="/users/218294/sam-watkins"
                       title="5,669 reputation"
                       class="comment-user">Sam Watkins</a>
                <span class="comment-date" dir="ltr"><span title="2012-03-08 03:22:35Z, License: CC BY-SA 3.0" class="relativetime-clean">Mar 8 '12 at 3:22</span></span>
                        <span title="this comment was edited 3 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-13887901" class="comment js-comment " data-comment-id="13887901">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I added some simpler regexps for extracting tags, text, and attributes, for XML / XHTML.</span>
                
&ndash;&nbsp;<a href="/users/218294/sam-watkins"
                       title="5,669 reputation"
                       class="comment-user">Sam Watkins</a>
                <span class="comment-date" dir="ltr"><span title="2012-05-22 08:00:48Z, License: CC BY-SA 3.0" class="relativetime-clean">May 22 '12 at 8:00</span></span>
            </div>
        </div>
    </li>
    <li id="comment-66191097" class="comment js-comment " data-comment-id="66191097">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">(get attributes bug 1) <code>&#47;(\w+)=&quot;(.*?)&quot;&#47;</code> assumes double quotes. It will miss values in single quotes. In html version 4 and earlier unquoted value is allowed, if it is a simple word.</span>
                
&ndash;&nbsp;<a href="/users/904933/david-andersson"
                       title="649 reputation"
                       class="comment-user">David Andersson</a>
                <span class="comment-date" dir="ltr"><span title="2016-09-11 08:23:51Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 11 '16 at 8:23</span></span>
            </div>
        </div>
    </li>
    <li id="comment-66191152" class="comment js-comment " data-comment-id="66191152">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">(get attributes bug 2) <code>&#47;(\w+)=&quot;(.*?)&quot;&#47;</code> may falsely match text that looks like an attribute within an attribute, e.g. <code>&lt;img title=&quot;Nope down=&#39;up&#39; for aussies&quot; src=&quot;...&quot; &#47;&gt;</code>. If applied globally, it will also match such things in ordinary text or in html comments.</span>
                
&ndash;&nbsp;<a href="/users/904933/david-andersson"
                       title="649 reputation"
                       class="comment-user">David Andersson</a>
                <span class="comment-date" dir="ltr"><span title="2016-09-11 08:28:54Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 11 '16 at 8:28</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-6653839" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>4</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="3274138"></a>
<div id="answer-3274138" class="answer" data-answerid="3274138"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="3274138">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="74">74</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/3274138/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>Here is a <a href="http://kingdesk.com/projects/php-parser/" rel="noreferrer">PHP based parser</a> that parses HTML using  some ungodly regex. As the author of this project, I can tell you it is possible to parse HTML with regex, but not efficient. If you need a server-side solution (as I did for my <a href="http://wordpress.org/extend/plugins/wp-typography/" rel="noreferrer">wp-Typography WordPress plugin</a>), this works.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2010-07-18T02:52:04"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/3274138"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/3274138/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-3274138" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/3274138/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title="2010-07-18 02:52:04Z" class="relativetime">Jul 18 '10 at 2:52</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jul 18 &#39;10 at 2:52. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-3274138" href="/posts/3274138/revisions" title="show revision history for this post">
        kingjeffrey
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-3274138" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="3274138" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-6906658" class="comment js-comment " data-comment-id="6906658">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy"><a href="http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/index.php" rel="nofollow noreferrer">htmlawed</a> is another PHP project that parses HTML to filter, convert, etc. Has some nice code if you can figure it out!</span>
                
&ndash;&nbsp;<a href="/users/594694/user594694"
                       title="327 reputation"
                       class="comment-user">user594694</a>
                <span class="comment-date" dir="ltr"><span title="2011-05-12 19:22:03Z, License: CC BY-SA 3.0" class="relativetime-clean">May 12 '11 at 19:22</span></span>
            </div>
        </div>
    </li>
    <li id="comment-43101483" class="comment js-comment " data-comment-id="43101483">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">No you <b>can’t</b> parse HTML with regex. But for some subsets, it <i>may</i> work.</span>
                
&ndash;&nbsp;<a href="/users/2171120/mirabilos"
                       title="4,111 reputation"
                       class="comment-user">mirabilos</a>
                <span class="comment-date" dir="ltr"><span title="2014-12-05 17:07:49Z, License: CC BY-SA 3.0" class="relativetime-clean">Dec 5 '14 at 17:07</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-3274138" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="2708960"></a>
<div id="answer-2708960" class="answer" data-answerid="2708960"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="2708960">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="71">71</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2708960/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>There are some nice regexes for replacing HTML with BBCode <a href="http://www.garyshood.com/htmltobb/source.txt" rel="noreferrer">here</a>. For all you nay-sayers, note that he's not trying to fully parse HTML, just to sanitize it. He can probably afford to kill off tags that his simple "parser" can't understand.</p>

<p>For example:</p>

<pre><code>$store =~ s/http:/http:\/\//gi;
$store =~ s/https:/https:\/\//gi;
$baseurl = $store;

if (!$query-&gt;param("ascii")) {
    $html =~ s/\s\s+/\n/gi;
    $html =~ s/&lt;pre(.*?)&gt;(.*?)&lt;\/pre&gt;/\[code]$2\[\/code]/sgmi;
}

$html =~ s/\n//gi;
$html =~ s/\r\r//gi;
$html =~ s/$baseurl//gi;
$html =~ s/&lt;h[1-7](.*?)&gt;(.*?)&lt;\/h[1-7]&gt;/\n\[b]$2\[\/b]\n/sgmi;
$html =~ s/&lt;p&gt;/\n\n/gi;
$html =~ s/&lt;br(.*?)&gt;/\n/gi;
$html =~ s/&lt;textarea(.*?)&gt;(.*?)&lt;\/textarea&gt;/\[code]$2\[\/code]/sgmi;
$html =~ s/&lt;b&gt;(.*?)&lt;\/b&gt;/\[b]$1\[\/b]/gi;
$html =~ s/&lt;i&gt;(.*?)&lt;\/i&gt;/\[i]$1\[\/i]/gi;
$html =~ s/&lt;u&gt;(.*?)&lt;\/u&gt;/\[u]$1\[\/u]/gi;
$html =~ s/&lt;em&gt;(.*?)&lt;\/em&gt;/\[i]$1\[\/i]/gi;
$html =~ s/&lt;strong&gt;(.*?)&lt;\/strong&gt;/\[b]$1\[\/b]/gi;
$html =~ s/&lt;cite&gt;(.*?)&lt;\/cite&gt;/\[i]$1\[\/i]/gi;
$html =~ s/&lt;font color="(.*?)"&gt;(.*?)&lt;\/font&gt;/\[color=$1]$2\[\/color]/sgmi;
$html =~ s/&lt;font color=(.*?)&gt;(.*?)&lt;\/font&gt;/\[color=$1]$2\[\/color]/sgmi;
$html =~ s/&lt;link(.*?)&gt;//gi;
$html =~ s/&lt;li(.*?)&gt;(.*?)&lt;\/li&gt;/\[\*]$2/gi;
$html =~ s/&lt;ul(.*?)&gt;/\[list]/gi;
$html =~ s/&lt;\/ul&gt;/\[\/list]/gi;
$html =~ s/&lt;div&gt;/\n/gi;
$html =~ s/&lt;\/div&gt;/\n/gi;
$html =~ s/&lt;td(.*?)&gt;/ /gi;
$html =~ s/&lt;tr(.*?)&gt;/\n/gi;

$html =~ s/&lt;img(.*?)src="(.*?)"(.*?)&gt;/\[img]$baseurl\/$2\[\/img]/gi;
$html =~ s/&lt;a(.*?)href="(.*?)"(.*?)&gt;(.*?)&lt;\/a&gt;/\[url=$baseurl\/$2]$4\[\/url]/gi;
$html =~ s/\[url=$baseurl\/http:\/\/(.*?)](.*?)\[\/url]/\[url=http:\/\/$1]$2\[\/url]/gi;
$html =~ s/\[img]$baseurl\/http:\/\/(.*?)\[\/img]/\[img]http:\/\/$1\[\/img]/gi;

$html =~ s/&lt;head&gt;(.*?)&lt;\/head&gt;//sgmi;
$html =~ s/&lt;object&gt;(.*?)&lt;\/object&gt;//sgmi;
$html =~ s/&lt;script(.*?)&gt;(.*?)&lt;\/script&gt;//sgmi;
$html =~ s/&lt;style(.*?)&gt;(.*?)&lt;\/style&gt;//sgmi;
$html =~ s/&lt;title&gt;(.*?)&lt;\/title&gt;//sgmi;
$html =~ s/&lt;!--(.*?)--&gt;/\n/sgmi;

$html =~ s/\/\//\//gi;
$html =~ s/http:\//http:\/\//gi;
$html =~ s/https:\//https:\/\//gi;

$html =~ s/&lt;(?:[^&gt;'"]*|(['"]).*?\1)*&gt;//gsi;
$html =~ s/\r\r//gi;
$html =~ s/\[img]\//\[img]/gi;
$html =~ s/\[url=\//\[url=/gi;
</code></pre>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2010-04-25T16:38:42"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/2708960"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/2708960/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-2708960" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/2708960/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2015-05-19 16:20:44Z" class="relativetime">May 19 '15 at 16:20</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Apr 25 &#39;10 at 16:38. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2708960" href="/posts/2708960/revisions" title="show revision history for this post">
        4 revs, 4 users 88%<br><a href="/users/55075">kenorb</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-2708960" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="2708960" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-52604067" class="comment js-comment " data-comment-id="52604067">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">15</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Don&#39;t do this. Please.</span>
                
&ndash;&nbsp;<a href="/users/381285/maletor"
                       title="6,362 reputation"
                       class="comment-user">maletor</a>
                <span class="comment-date" dir="ltr"><span title="2015-09-03 02:12:42Z, License: CC BY-SA 3.0" class="relativetime-clean">Sep 3 '15 at 2:12</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-2708960" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="3180176"></a>
<div id="answer-3180176" class="answer" data-answerid="3180176"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="3180176">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="68">68</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/3180176/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>About the question of the RegExp methods to parse (x)HTML, the answer to all of the ones who spoke about some limits is: you have not been trained enough to rule the force of this powerful weapon, since <strong>NOBODY</strong> here spoke about <strong>recursion</strong>.</p>

<p>A RegExp-agnostic colleague notified me this discussion, which is not certainly the first on the web about this old and hot topic.</p>

<p>After reading some posts, the first thing I did was looking for the "?R" string in this thread. The second was to search about "recursion".<br>
No, holy cow, no match found.<br>
Since nobody mentioned the main mechanism a parser is built onto, I was soon aware that nobody got the point.</p>

<p>If an (x)HTML parser needs recursion, a RegExp parser without recursion is not enough for the purpose. It's a simple construct.</p>

<p>The <strong>black art of RegExp is hard to master</strong>, so maybe there are further possibilities we left out while trying and testing our personal solution to capture the whole web in one hand... Well, I am sure about it :)</p>

<p>Here's the magic pattern:</p>

<pre><code>$pattern = "/&lt;([\w]+)([^&gt;]*?)(([\s]*\/&gt;)|(&gt;((([^&lt;]*?|&lt;\!\-\-.*?\-\-&gt;)|(?R))*)&lt;\/\\1[\s]*&gt;))/s";
</code></pre>

<p>Just try it.<br>
It's written as a PHP string, so the "s" modifier makes classes include newlines.<br />
Here's a <strong>sample note on the PHP manual</strong> I wrote on January: <a href="http://php.net/manual/en/regexp.reference.recursive.php" rel="noreferrer">Reference</a></p>

<p>(Take care, in that note I wrongly used the "m" modifier; it should be erased, notwithstanding it is discarded by the RegExp engine, since no ^ or $ anchorage was used).</p>

<p>Now, we could speak about the limits of this method from a more informed point of view:</p>

<ol>
<li>according to the specific implementation of the RegExp engine, recursion may have a limit in the <strong>number of nested patterns parsed</strong>, but it depends on the language used</li>
<li>although corrupted (x)HTML does not drive into severe errors, it is not <em>sanitized</em>.</li>
</ol>

<p>Anyhow it is only a RegExp pattern, but it discloses the possibility to develop of a lot of powerful implementations.<br>
I wrote this pattern to power the <em>recursive descent parser</em> of a template engine I built in my framework, and performances are really great, both in execution times or in memory usage (nothing to do with other template engines which use the same syntax).</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2010-07-05T14:16:50"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/3180176"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/3180176/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-3180176" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/3180176/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2014-11-18 16:17:16Z" class="relativetime">Nov 18 '14 at 16:17</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jul 5 &#39;10 at 14:16. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-3180176" href="/posts/3180176/revisions" title="show revision history for this post">
        3 revs, 3 users 75%<br><a href="/users/383764">Emanuele Del Grande</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-3180176" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="3180176" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="7"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-3275117" class="comment js-comment " data-comment-id="3275117">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">35</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I&#39;ll put this in the &quot;Regex which doesn&#39;t allow greater-than in attributes&quot; bin. Check it against &lt;input value=&quot;is 5 &gt; 3?&quot; /&gt;</span>
                
&ndash;&nbsp;<a href="/users/31582/gareth"
                       title="106,420 reputation"
                       class="comment-user">Gareth</a>
                <span class="comment-date" dir="ltr"><span title="2010-07-05 16:24:02Z, License: CC BY-SA 2.5" class="relativetime-clean">Jul 5 '10 at 16:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3275182" class="comment js-comment " data-comment-id="3275182">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">68</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">If you put something like that in production code, you would likely be shot by the maintainer.  A jury would never convict him.</span>
                
&ndash;&nbsp;<a href="/users/72943/aehiilrs"
                       title="1,225 reputation"
                       class="comment-user">aehiilrs</a>
                <span class="comment-date" dir="ltr"><span title="2010-07-05 16:33:01Z, License: CC BY-SA 2.5" class="relativetime-clean">Jul 5 '10 at 16:33</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3284978" class="comment js-comment " data-comment-id="3284978">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">30</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Regular expressions can&#39;t work because by definition they are not recursive. Adding a recursive operator to regular expressions basically makes a CFG only with poorer syntax. Why not use something designed to be recursive in the first place rather than violently insert recursion into something already overflowing with extraneous functionality?</span>
                
&ndash;&nbsp;<a href="/users/52443/welbog"
                       title="53,485 reputation"
                       class="comment-user">Welbog</a>
                <span class="comment-date" dir="ltr"><span title="2010-07-06 18:38:34Z, License: CC BY-SA 2.5" class="relativetime-clean">Jul 6 '10 at 18:38</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3321225" class="comment js-comment " data-comment-id="3321225">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">16</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">My objection isn&#39;t one of functionality it is one of time invested. The problem with RegEx is that by the time you post the cutsey little one liners it appears that you did something more efficiently (&quot;See one line of code!&quot;). And of course no one mentions the half hour (or 3) that they spent with their cheat-sheet and (hopefully) testing every possible permutation of input. And once you get past all that when the maintainer goes to figure out or validate the code they can&#39;t just look at it and see that it is right. The have to dissect the expression and essentially retest it all over again...</span>
                
&ndash;&nbsp;<a href="/users/102270/oorang"
                       title="6,030 reputation"
                       class="comment-user">Oorang</a>
                <span class="comment-date" dir="ltr"><span title="2010-07-10 15:11:09Z, License: CC BY-SA 2.5" class="relativetime-clean">Jul 10 '10 at 15:11</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3321252" class="comment js-comment " data-comment-id="3321252">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">15</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">... to know that it is good. And that will happen even with people who are <i>good</i> with regex. And honestly I suspect that overwhelming majority of people won&#39;t know it well. So you take one of the most notorious maintenance nightmares and combine it with recursion which is the <i>other</i> maintenance nightmare and I think to myself what I really need on my project is someone a little less clever. The goal is to write code that bad programmers can maintain without breaking the code base. I know it galls to code to the least common denominator. But hiring excellent talent is hard, and you often...</span>
                
&ndash;&nbsp;<a href="/users/102270/oorang"
                       title="6,030 reputation"
                       class="comment-user">Oorang</a>
                <span class="comment-date" dir="ltr"><span title="2010-07-10 15:17:22Z, License: CC BY-SA 2.5" class="relativetime-clean">Jul 10 '10 at 15:17</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-3180176" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="expand to show all comments on this post" href=# onclick="" role="button">show <b>7</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="2201251"></a>
<div id="answer-2201251" class="answer" data-answerid="2201251"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="2201251">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="62">62</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2201251/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>As many people have already pointed out, HTML is not a regular language which can make it very difficult to parse. My solution to this is to turn it into a regular language using a tidy program and then to use an XML parser to consume the results. There are a lot of good options for this. My program is written using Java with the <a href="http://jtidy.sourceforge.net/" rel="noreferrer">jtidy</a> library to turn the HTML into XML and then Jaxen to xpath into the result.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2010-02-04T16:22:00"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/2201251"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/2201251/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-2201251" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/2201251/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title="2010-02-04 16:22:00Z" class="relativetime">Feb 4 '10 at 16:22</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Feb 4 &#39;10 at 16:22. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2201251" href="/posts/2201251/revisions" title="show revision history for this post">
        Corey Sanders
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-2201251" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="2201251" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-2201251" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="10535487"></a>
<div id="answer-10535487" class="answer" data-answerid="10535487"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="10535487">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="61">61</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10535487/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<pre><code>&lt;\s*(\w+)[^/&gt;]*&gt;
</code></pre>

<p>The parts explained:</p>

<p><code>&lt;</code>: starting character</p>

<p><code>\s*</code>: it may have whitespaces before tag name (ugly but possible).</p>

<p><code>(\w+)</code>: tags can contain letters and numbers (h1). Well, <code>\w</code> also matches '_', but it does not hurt I guess. If curious use ([a-zA-Z0-9]+) instead.</p>

<p><code>[^/&gt;]*</code>: anything except <code>&gt;</code> and <code>/</code> until closing <code>&gt;</code></p>

<p><code>&gt;</code>: closing <code>&gt;</code></p>

<h3>UNRELATED</h3>

<p>And to fellows who underestimate regular expressions saying they are only as powerful as regular languages:</p>

<p>a<sup>n</sup>ba<sup>n</sup>ba<sup>n</sup> which is not regular and not even context free, can be matched with <code>^(a+)b\1b\1$</code></p>

<p>Backreferencing <a href="http://en.wiktionary.org/wiki/FTW" rel="noreferrer">FTW</a>!</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2012-05-10T13:53:54"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/10535487"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/10535487/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-10535487" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10535487/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2015-03-28 12:17:38Z" class="relativetime">Mar 28 '15 at 12:17</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of May 10 &#39;12 at 13:53. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10535487" href="/posts/10535487/revisions" title="show revision history for this post">
        5 revs, 4 users 73%<br><a href="/users/277291">daghan</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-10535487" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="10535487" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-20494033" class="comment js-comment " data-comment-id="20494033">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@GlitchMr, that was his point. Modern regular expressions are not technically regular, nor is there any reason for them to be.</span>
                
&ndash;&nbsp;<a href="/users/873843/alanaktion"
                       title="1,278 reputation"
                       class="comment-user">alanaktion</a>
                <span class="comment-date" dir="ltr"><span title="2013-02-02 15:45:29Z, License: CC BY-SA 3.0" class="relativetime-clean">Feb 2 '13 at 15:45</span></span>
            </div>
        </div>
    </li>
    <li id="comment-20863430" class="comment js-comment " data-comment-id="20863430">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@alanaktion: The &quot;modern&quot; regular expressions (read: with Perl extensions) cannot match within <code>O(MN)</code> (M being regular expression length, N being text length). Backreferences are one of causes of that. The implementation in awk doesn&#39;t have backreferences and matches everything within <code>O(MN)</code> time.</span>
                
&ndash;&nbsp;<a href="/users/736054/konrad-borowski"
                       title="9,077 reputation"
                       class="comment-user">Konrad Borowski</a>
                <span class="comment-date" dir="ltr"><span title="2013-02-14 16:52:45Z, License: CC BY-SA 3.0" class="relativetime-clean">Feb 14 '13 at 16:52</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-10535487" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="10844758"></a>
<div id="answer-10844758" class="answer" data-answerid="10844758"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="10844758">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="56">56</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10844758/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>If you're simply trying to find those tags (without ambitions of parsing) try this regular expression:</p>

<pre><code>/&lt;[^/]*?&gt;/g
</code></pre>

<p>I wrote it in 30 seconds, and tested here:
<a href="http://gskinner.com/RegExr/">http://gskinner.com/RegExr/</a></p>

<p>It matches the types of tags you mentioned, while ignoring the types you said you wanted to ignore.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2012-06-01T05:13:26"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/10844758"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/10844758/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-10844758" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10844758/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2016-05-31 07:23:30Z" class="relativetime">May 31 '16 at 7:23</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jun 1 &#39;12 at 5:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10844758" href="/posts/10844758/revisions" title="show revision history for this post">
        6 revs, 2 users 96%<br><a href="/users/217867">Lonnie Best</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-10844758" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="10844758" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-43567564" class="comment js-comment " data-comment-id="43567564">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I think you mean <code>\&#47;&gt;</code> instead of <code>\\&gt;</code>.</span>
                
&ndash;&nbsp;<a href="/users/399649/justin-morgan"
                       title="25,998 reputation"
                       class="comment-user">Justin Morgan</a>
                <span class="comment-date" dir="ltr"><span title="2014-12-19 17:36:51Z, License: CC BY-SA 3.0" class="relativetime-clean">Dec 19 '14 at 17:36</span></span>
                        <span title="this comment was edited 5 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-62508271" class="comment js-comment " data-comment-id="62508271">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">No, just <code>\&gt;</code> is what I meant; I never meant to edit the regular expression of my original post.</span>
                
&ndash;&nbsp;<a href="/users/217867/lonnie-best"
                       title="5,479 reputation"
                       class="comment-user">Lonnie Best</a>
                <span class="comment-date" dir="ltr"><span title="2016-05-29 06:38:04Z, License: CC BY-SA 3.0" class="relativetime-clean">May 29 '16 at 6:38</span></span>
            </div>
        </div>
    </li>
    <li id="comment-62509129" class="comment js-comment " data-comment-id="62509129">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">FYI, you don&#39;t need to escape angle brackets.  Of course, it does no harm to escape them anyway, but look at the confusion you could have avoided. ;)</span>
                
&ndash;&nbsp;<a href="/users/20938/alan-moore"
                       title="65,747 reputation"
                       class="comment-user">Alan Moore</a>
                <span class="comment-date" dir="ltr"><span title="2016-05-29 07:47:04Z, License: CC BY-SA 3.0" class="relativetime-clean">May 29 '16 at 7:47</span></span>
            </div>
        </div>
    </li>
    <li id="comment-62568124" class="comment js-comment " data-comment-id="62568124">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I sometimes escape unnecessarily when I&#39;m unsure if something is special character or not. I&#39;ve edited the answer; it works the same but more concise.</span>
                
&ndash;&nbsp;<a href="/users/217867/lonnie-best"
                       title="5,479 reputation"
                       class="comment-user">Lonnie Best</a>
                <span class="comment-date" dir="ltr"><span title="2016-05-31 07:23:11Z, License: CC BY-SA 3.0" class="relativetime-clean">May 31 '16 at 7:23</span></span>
            </div>
        </div>
    </li>
    <li id="comment-62640885" class="comment js-comment " data-comment-id="62640885">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Looking at this now, I don&#39;t know why I thought you meant <code>\&#47;</code>, since that would do the exact opposite of the requirements. Maybe I thought you were offering a negative filter pattern.</span>
                
&ndash;&nbsp;<a href="/users/399649/justin-morgan"
                       title="25,998 reputation"
                       class="comment-user">Justin Morgan</a>
                <span class="comment-date" dir="ltr"><span title="2016-06-01 19:14:20Z, License: CC BY-SA 3.0" class="relativetime-clean">Jun 1 '16 at 19:14</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-10844758" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="1738126"></a>
<div id="answer-1738126" class="answer" data-answerid="1738126"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="1738126">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="54">54</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1738126/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>It seems to me you're trying to match tags without a "/" at the end. Try this:</p>

<pre><code>&lt;([a-zA-Z][a-zA-Z0-9]*)[^&gt;]*(?&lt;!/)&gt;
</code></pre>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2009-11-15T17:13:19"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/1738126"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/1738126/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-1738126" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/1738126/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title="2009-11-15 17:13:19Z" class="relativetime">Nov 15 '09 at 17:13</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19 &#39;09 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1738126" href="/posts/1738126/revisions" title="show revision history for this post">
        manixrock
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-1738126" class="comments js-comments-container bt bc-black-2 mt12 " data-post-id="1738126" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-6771435" class="comment js-comment " data-comment-id="6771435">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">8</span>
            </div>
        </div>
        <div class="comment-text js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">This does not work. For the input &#39;&lt;x a=&quot;&lt;b&gt;&quot;/&gt;&lt;y&gt;&#39; the matches are x and y, although x is terminated.</span>
                
&ndash;&nbsp;<a href="/users/402322/ceving"
                       title="15,124 reputation"
                       class="comment-user">ceving</a>
                <span class="comment-date" dir="ltr"><span title="2011-05-04 16:33:18Z, License: CC BY-SA 3.0" class="relativetime-clean">May 4 '11 at 16:33</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1738126" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="10791453"></a>
<div id="answer-10791453" class="answer" data-answerid="10791453"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="10791453">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="51">51</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10791453/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>It's true that when programming it's usually best to use dedicated parsers and APIs instead of regular expressions when dealing with HTML, especially if accuracy is paramount (e.g., if your processing might have security implications). However, I don’t ascribe to a dogmatic view that XML-style markup should never be processed with regular expressions. There are cases when regular expressions are a great tool for the job, such as when making one-time edits in a text editor, fixing broken XML files, or dealing with file formats that look like but aren’t quite XML. There are some issues to be aware of, but they're not insurmountable or even necessarily relevant.</p>

<p>A simple regex like <code>&lt;([^&gt;"']|"[^"]*"|'[^']*')*&gt;</code> is usually good enough, in cases such as those I just mentioned. It's a naive solution, all things considered, but it does correctly allow unencoded <code>&gt;</code> symbols in attribute values. If you're looking for, e.g., a <code>table</code> tag, you could adapt it as <code>&lt;/?table\b([^&gt;"']|"[^"]*"|'[^']*')*&gt;</code>.</p>

<p>Just to give a sense of what a more "advanced" HTML regex would look like, the following does a fairly respectable job of emulating real-world browser behavior and the HTML5 parsing algorithm:</p>

<pre><code>&lt;/?([A-Za-z][^\s&gt;/]*)(?:=\s*(?:"[^"]*"|'[^']*'|[^\s&gt;]+)|[^&gt;])*(?:&gt;|$)
</code></pre>

<p>The following matches a fairly strict definition of XML tags (although it doesn't account for the full set of Unicode characters allowed in XML names):</p>

<pre><code>&lt;(?:([_:A-Z][-.:\w]*)(?:\s+[_:A-Z][-.:\w]*\s*=\s*(?:"[^"]*"|'[^']*'))*\s*/?|/([_:A-Z][-.:\w]*)\s*)&gt;
</code></pre>

<p>Granted, these don't account for surrounding context and a few edge cases, but even such things could be dealt with if you really wanted to (e.g., by searching between the matches of another regex).</p>

<p>At the end of the day, use the most appropriate tool for the job, even in the cases when that tool happens to be a regex.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2012-05-28T23:27:06"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/10791453"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
       data-se-share-sheet-license-name="CC BY-SA 3.0"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/10791453/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-10791453" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10791453/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title="2012-05-29 00:01:51Z" class="relativetime">May 29 '12 at 0:01</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of May 28 &#39;12 at 23:27. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10791453" href="/posts/10791453/revisions" title="show revision history for this post">
        2 revs<br><a href="/users/1421022">slevithan</a>
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-10791453" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="10791453" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-10791453" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                          
<a name="2226652"></a>
<div id="answer-2226652" class="answer" data-answerid="2226652"  itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="2226652">
        <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Upvote this answer if you find it clear and useful." aria-pressed="false" aria-label="Up vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"/></svg></button>
        <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="49">49</div>
        <button class="js-vote-down-btn grid--cell s-btn s-btn__unset c-pointer" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Downvote this answer if you find it unclear or not useful." aria-pressed="false" aria-label="Down vote" data-selected-classes="fc-theme-primary"><svg aria-hidden="true" class="m0 svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 10h32L18 26 2 10z"/></svg></button>

    
            <div class="js-accepted-answer-indicator grid--cell fc-green-500 ta-center py4 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8v-8z"/></svg>
            </div>

        
<div class="js-reactions grid--cell"
     data-controller="reactions"
     data-count="0"
     data-action="post:reactionsInit->reactions#updateUI">
        <button class="s-btn s-btn__unset w100 py4 c-pointer" aria-label="Thanks (0)" data-target="reactions.button" data-action="reactions#tryToggle keypress->reactions#tryToggle" aria-pressed="false"
                data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="Say &lt;b&gt;thanks&lt;/b&gt; for this answer."><svg aria-hidden="true" class="svg-icon iconHandsTogether" width="18" height="18" viewBox="0 0 18 18"><path d="M3.85 1.15a.5.5 0 10-.7.7l2 2a.5.5 0 10.7-.7l-2-2zM5.5 6h-2a.5.5 0 000 1h2a.5.5 0 000-1zm10 1h-2a.5.5 0 010-1h2a.5.5 0 010 1zm.35-5.15a.5.5 0 00-.7-.7l-2 2a.5.5 0 00.7.7l2-2z" opacity=".4"/><path d="M8.21 16.49c-.44.37-1.02.55-1.6.51H5v-6h2l1-7.63c0-.2.23-.37.5-.37s.5.17.5.37V15a2.23 2.23 0 01-.79 1.49zm2.58 0c.44.37 1.02.55 1.6.51H14v-6h-2l-1-7.63c0-.2-.23-.37-.5-.37s-.5.17-.5.37V15c.06.58.34 1.11.79 1.49z" fill="#FFC166"/><path d="M2.5 11c-.83 0-1.5.67-1.5 1.5v3c0 .83.67 1.5 1.5 1.5H4v-6H2.5zm14 0H15v6h1.5c.83 0 1.5-.67 1.5-1.5v-3c0-.83-.67-1.5-1.5-1.5z" opacity=".7" fill="#07C"/></svg></button>
        <div class="ta-center fc-black-200 d-none" data-target="reactions.count"
             data-controller="s-tooltip" data-s-tooltip-placement="right" data-s-tooltip-html-title="0 others reacted with &lt;b&gt;thanks&lt;/b&gt;.">0</div>
</div>

    
        <a class="js-post-issue grid--cell s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2226652/timeline" data-shortcut="T" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 113.73 6.77L8.2 14.3A6 6 0 105 9l3.01-.01-4 4-4-4h3L3 9zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="post-text" itemprop="text">
<p>Although it's not suitable and effective to use regular expressions for that purpose sometimes regular expressions provide quick solutions for simple match problems and in my view it's not that horrbile to use regular expressions for trivial works. </p>

<p>There is a <a href="http://blog.stevenlevithan.com/archives/match-innermost-html-element" rel="noreferrer">definitive blog post</a> about matching innermost HTML elements written by Steven Levithan.</p>
    </div>
    <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy">
        <time itemprop="dateCreated" datetime="2010-02-09T03:59:27"></time>
        <div class="grid--cell mr16" style="flex: 1 1 100px;">
            

<div class="post-menu">
    <a href="/a/2226652"
       rel="nofollow"
       itemprop="url"
       class="js-share-link js-gps-track"
       title="short permalink to this answer"
       data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
       data-controller="se-share-sheet"
       data-se-share-sheet-title="Share a link to this answer"
       data-se-share-sheet-subtitle=""
       data-se-share-sheet-post-type="answer"
       data-se-share-sheet-social="facebook twitter devto"
       data-se-share-sheet-location="2"
       data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
       data-se-share-sheet-license-name="CC BY-SA 2.5"
       data-s-popover-placement="bottom-start">share</a>
        <span class="lsep">|</span>
                <a href="/posts/2226652/edit" class="suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: 0, post_type: 2 })" title="">improve this answer</a>
        <span class="lsep">|</span>
    <button id="btnFollowPost-2226652" class="s-btn s-btn__link fc-black-400 h:fc-black-700 pb2 js-follow-post js-follow-answer js-gps-track" role="button"
            data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
            data-controller="s-tooltip " data-s-tooltip-placement="bottom"
            data-s-popover-placement="bottom" aria-controls=""
            title="Follow this answer to receive notifications">
        follow
    </button>
        <span class="lsep">|</span>
</div>

        </div>
    <div class="post-signature grid--cell fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/2226652/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title="2010-02-09 03:59:27Z" class="relativetime">Feb 9 '10 at 3:59</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>    </div>


    <div class="post-signature grid--cell fl0">
        <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Feb 9 &#39;10 at 3:59. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2226652" href="/posts/2226652/revisions" title="show revision history for this post">
        Emre Yazici
        </a>
    </div>
</div>

    </div>
    </div>
    
</div>


                <div class="post-layout--right">
        <div id="comments-2226652" class="comments js-comments-container bt bc-black-2 mt12  dno" data-post-id="2226652" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-2226652" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Say thanks by reacting to the answer."  href="#" role="button">add a comment</a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

<div class="s-pagination pager-answers">
<div class="s-pagination--item is-selected">1</div>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=votes#tab-top" rel="" title="Go to page 2">2</a>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=votes#tab-top" rel="next" title="Go to page 2"> Next</a></div>

                                <aside class="s-notice s-notice__info js-post-notice mb16" role="status">
        <div class="grid fd-column fw-nowrap">
            <div class="grid fw-nowrap">
                    <div class="grid--cell mr8">
                        <svg aria-hidden="true" class="svg-icon iconFire" width="18" height="18" viewBox="0 0 18 18"><path opacity=".6" d="M13.18 9c-.8.33-1.46.6-1.97 1.3A9.21 9.21 0 0010 13.89a10 10 0 001.32-.8 2.53 2.53 0 01-.63 2.91h.78a3 3 0 001.66-.5 4.15 4.15 0 001.26-1.61c.4-.96.47-1.7.55-2.73.05-1.24-.1-2.49-.46-3.68a2 2 0 01-.4.91 2.1 2.1 0 01-.9.62z" fill="#FF6700"/><path d="M10.4 12.11a7.1 7.1 0 01.78-1.76c.3-.47.81-.8 1.37-1.08 0 0-.05-3.27-1.55-5.27-1.5-2-3.37-2.75-4.95-2.61 0 0 3.73 2.42.72 5.15C4.63 8.45 3.59 10.87 4.13 13a4.14 4.14 0 003.1 3 4.05 4.05 0 011.08-3.89C9.42 10.92 8 9.79 8 9.79c.67.02 1.3.28 1.81.72a2 2 0 01.58 1.6z" fill="#EF2E2E"/></svg>
                    </div>
                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        <b><a href="/help/privileges/protect-questions">Highly active question</a></b>. Earn 10 reputation in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
                        
                    </div>
                </div>
            </div>
        </div>
</aside>




                            <h2 class="bottom-notice" data-loc="1">
Not the answer you&#x27;re looking for? Browse other questions tagged <a href="/questions/tagged/html" class="post-tag" title="show questions tagged &#39;html&#39;" rel="tag">html</a> <a href="/questions/tagged/regex" class="post-tag" title="show questions tagged &#39;regex&#39;" rel="tag">regex</a> <a href="/questions/tagged/xhtml" class="post-tag" title="show questions tagged &#39;xhtml&#39;" rel="tag">xhtml</a>  or <a href="/questions/ask">ask your own question</a>.                            </h2>
                </div>
            </div>
            <div id="sidebar" class="show-votes" role="complementary" aria-label="sidebar">
                
<div class="s-sidebarwidget s-sidebarwidget__yellow s-anchors s-anchors__grayscale mb16" data-tracker="cb=1">
                <div class="s-sidebarwidget--header s-sidebarwidget__small-bold-text fc-light d:fc-black-900">
                    The Overflow Blog
                </div>
            <ul class="s-sidebarwidget--content s-sidebarwidget__items pt0 pr16 pb0 pl16">
    <li class="s-sidebarwidget--item grid">
        <div class="grid--cell1 fl-shrink0">
                <a href="https://stackoverflow.blog/2020/06/19/podcast-245-it-aint-real-till-you-break-prod/" data-ga="[&quot;community bulletin board&quot;,&quot;The Overflow Blog&quot;,&quot;https://stackoverflow.blog/2020/06/19/podcast-245-it-aint-real-till-you-break-prod/&quot;,null,null]">
<svg aria-hidden="true" class="va-text-top svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>                </a>
        </div>
        <div class="grid--cell">
            <a href="https://stackoverflow.blog/2020/06/19/podcast-245-it-aint-real-till-you-break-prod/" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;The Overflow Blog&quot;,&quot;https://stackoverflow.blog/2020/06/19/podcast-245-it-aint-real-till-you-break-prod/&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 1, position: 0 })">Podcast 245: It ain’t real till you break Prod</a>
        </div>
    </li>
            </ul>
            <ul class="s-sidebarwidget--content s-sidebarwidget__items pt0 pr16 pb0 pl16">
    <li class="s-sidebarwidget--item grid">
        <div class="grid--cell1 fl-shrink0">
                <a href="https://stackoverflow.blog/2020/06/19/16125/" data-ga="[&quot;community bulletin board&quot;,&quot;The Overflow Blog&quot;,&quot;https://stackoverflow.blog/2020/06/19/16125/&quot;,null,null]">
<svg aria-hidden="true" class="va-text-top svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="M11.1 1.71l1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0zM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88z"/></svg>                </a>
        </div>
        <div class="grid--cell">
            <a href="https://stackoverflow.blog/2020/06/19/16125/" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;The Overflow Blog&quot;,&quot;https://stackoverflow.blog/2020/06/19/16125/&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 1, position: 1 })">The Overflow #26: The next right thing</a>
        </div>
    </li>
            </ul>
                <div class="s-sidebarwidget--header s-sidebarwidget__small-bold-text fc-light d:fc-black-900">
                    Featured on Meta
                </div>
            <ul class="s-sidebarwidget--content s-sidebarwidget__items pt0 pr16 pb0 pl16">
    <li class="s-sidebarwidget--item grid">
        <div class="grid--cell1 fl-shrink0">
                <a href="https://meta.stackexchange.com/questions/348746/were-switching-to-commonmark" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackexchange.com/questions/348746/were-switching-to-commonmark&quot;,null,null]">
<div class="favicon favicon-stackexchangemeta" title="Meta Stack Exchange"></div>                </a>
        </div>
        <div class="grid--cell">
            <a href="https://meta.stackexchange.com/questions/348746/were-switching-to-commonmark" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackexchange.com/questions/348746/were-switching-to-commonmark&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 3, position: 2 })">We&#39;re switching to CommonMark</a>
        </div>
    </li>
            </ul>
            <ul class="s-sidebarwidget--content s-sidebarwidget__items pt0 pr16 pb0 pl16">
    <li class="s-sidebarwidget--item grid">
        <div class="grid--cell1 fl-shrink0">
                <a href="https://meta.stackexchange.com/questions/349276/new-post-lock-available-on-meta-sites-policy-lock" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackexchange.com/questions/349276/new-post-lock-available-on-meta-sites-policy-lock&quot;,null,null]">
<div class="favicon favicon-stackexchangemeta" title="Meta Stack Exchange"></div>                </a>
        </div>
        <div class="grid--cell">
            <a href="https://meta.stackexchange.com/questions/349276/new-post-lock-available-on-meta-sites-policy-lock" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackexchange.com/questions/349276/new-post-lock-available-on-meta-sites-policy-lock&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 3, position: 3 })">New post lock available on meta sites: Policy Lock</a>
        </div>
    </li>
            </ul>
            <ul class="s-sidebarwidget--content s-sidebarwidget__items pt0 pr16 pb0 pl16">
    <li class="s-sidebarwidget--item grid">
        <div class="grid--cell1 fl-shrink0">
                <a href="https://meta.stackoverflow.com/questions/398367/feature-test-thank-you-reaction" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackoverflow.com/questions/398367/feature-test-thank-you-reaction&quot;,null,null]">
<div class="favicon favicon-stackoverflowmeta" title="Meta Stack Overflow"></div>                </a>
        </div>
        <div class="grid--cell">
            <a href="https://meta.stackoverflow.com/questions/398367/feature-test-thank-you-reaction" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackoverflow.com/questions/398367/feature-test-thank-you-reaction&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 6, position: 4 })">Feature test: Thank you reaction</a>
        </div>
    </li>
            </ul>
</div>


<div id="dfp-tsb" class="everyonelovesstackoverflow everyoneloves__top-sidebar mb8"></div>
<div id="dfp-msb" class="everyonelovesstackoverflow everyoneloves__mid-sidebar mb8"></div>
<div id="hireme"></div>
                
                <div class="module sidebar-linked">
	<h4 id="h-linked">Linked</h4>
	<div class="linked" data-tracker="lq=1">
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 4456814, position: 0 })">
	<a href="/q/4456814" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes answered-accepted default">30</div>
	</a>
	<a href="/questions/4456814/writing-regular-expression-in-php-to-wrap-img-with-a?noredirect=1" class="question-hyperlink">Writing regular expression in PHP to wrap &lt;img&gt; with &lt;a&gt;</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 7532202, position: 1 })">
	<a href="/q/7532202" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes  default">0</div>
	</a>
	<a href="/questions/7532202/regular-expression-for-remove-html-links?noredirect=1" class="question-hyperlink">Regular expression for remove html links</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 820926, position: 2 })">
	<a href="/q/820926" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes answered-accepted default">9</div>
	</a>
	<a href="/questions/820926/regular-expression-to-remove-links?noredirect=1" class="question-hyperlink">regular expression to remove links</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 3604109, position: 3 })">
	<a href="/q/3604109" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes  default">8</div>
	</a>
	<a href="/questions/3604109/regexp-for-html?noredirect=1" class="question-hyperlink">Regexp for html</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 2826549, position: 4 })">
	<a href="/q/2826549" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes  default">5</div>
	</a>
	<a href="/questions/2826549/regular-expression-to-remove-div-tags?noredirect=1" class="question-hyperlink">Regular Expression to remove Div tags</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 10867836, position: 5 })">
	<a href="/q/10867836" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes answered-accepted default">9</div>
	</a>
	<a href="/questions/10867836/regex-convert-html-to-valid-xml-tag?noredirect=1" class="question-hyperlink">Regex - Convert HTML to valid XML tag</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 3593124, position: 6 })">
	<a href="/q/3593124" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes  default">6</div>
	</a>
	<a href="/questions/3593124/getting-text-from-inside-an-html-tag-within-a-local-file-with-grep?noredirect=1" class="question-hyperlink">Getting text from inside an HTML tag within a local file with grep</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 56945112, position: 7 })">
	<a href="/q/56945112" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes answered-accepted default">0</div>
	</a>
	<a href="/questions/56945112/how-to-split-html-string-using-javascript?noredirect=1" class="question-hyperlink">How to split html string using JavaScript</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 1061365, position: 8 })">
	<a href="/q/1061365" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes answered-accepted default">3</div>
	</a>
	<a href="/questions/1061365/building-regular-expression-regex-to-extract-text-of-html-tag?noredirect=1" class="question-hyperlink">Building Regular Expression (RegEx) to extract text of HTML tag</a>
</div>
		    
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 21152404, position: 9 })">
	<a href="/q/21152404" title="Vote score (upvotes - downvotes)">
		<div class="answer-votes answered-accepted default">1</div>
	</a>
	<a href="/questions/21152404/regular-expression-to-match-open-and-closed-html-tags?noredirect=1" class="question-hyperlink">Regular Expression to match open and closed html tags</a>
</div>
		    <div class="spacer more ml32 pl16 pt8">
                <a href="/questions/linked/1732348">See more linked questions</a>
            </div>
	</div>
</div>


                    <div class="module sidebar-related">
                        <h4 id="h-related">Related</h4>
                        <div class="related js-gps-related-questions" data-tracker="rq=1">
                            <div class="spacer"><a href="/q/80357" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted large">587</div></a><a href="/questions/80357/how-to-match-all-occurrences-of-a-regex" class="question-hyperlink">How to match all occurrences of a regex</a></div><div class="spacer"><a href="/q/406230" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted extra-large">4315</div></a><a href="/questions/406230/regular-expression-to-match-a-line-that-doesnt-contain-a-word" class="question-hyperlink">Regular expression to match a line that doesn&#39;t contain a word</a></div><div class="spacer"><a href="/q/1409162" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted large">345</div></a><a href="/questions/1409162/what-regex-will-match-every-character-except-comma-or-semi-colon" class="question-hyperlink">What regex will match every character except comma &#39;,&#39; or semi-colon &#39;;&#39;?</a></div><div class="spacer"><a href="/q/3558119" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted large">671</div></a><a href="/questions/3558119/are-non-void-self-closing-tags-valid-in-html5" class="question-hyperlink">Are (non-void) self-closing tags valid in HTML5?</a></div><div class="spacer"><a href="/q/5319840" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted large">358</div></a><a href="/questions/5319840/greedy-vs-reluctant-vs-possessive-quantifiers" class="question-hyperlink">Greedy vs. Reluctant vs. Possessive Quantifiers</a></div><div class="spacer"><a href="/q/6603015" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted large">759</div></a><a href="/questions/6603015/check-whether-a-string-matches-a-regex-in-js" class="question-hyperlink">Check whether a string matches a regex in JS</a></div><div class="spacer"><a href="/q/8085872" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted default">1</div></a><a href="/questions/8085872/python-regex-and-html-match-final-tag-on-line" class="question-hyperlink">Python, regex and html: match final tag on line</a></div><div class="spacer"><a href="/q/20429560" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted default">0</div></a><a href="/questions/20429560/regex-match-for-html-tag-containing-on-js-trigger" class="question-hyperlink">Regex match for HTML tag containing &ldquo;on&rdquo; JS trigger</a></div><div class="spacer"><a href="/q/29208984" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted default">86</div></a><a href="/questions/29208984/cannot-display-html-string" class="question-hyperlink">Cannot display HTML string</a></div><div class="spacer"><a href="/q/54961432" title="Vote score (upvotes - downvotes)"><div class="answer-votes answered-accepted default">1</div></a><a href="/questions/54961432/regex-excluding-matches-wrapped-in-specific-bbcode-tags" class="question-hyperlink">Regex excluding matches wrapped in specific bbcode tags</a></div>
                        </div>
                    </div>

                <div id="hot-network-questions" class="module tex2jax_ignore">
    <h4>
        <a href="https://stackexchange.com/questions?tab=hot"
           class="js-gps-track s-link s-link__inherit" 
           data-gps-track="posts_hot_network.click({ item_type:1, location:11 })">
            Hot Network Questions
        </a>
    </h4>
    <ul>
            <li >
                <div class="favicon favicon-hermeneutics" title="Biblical Hermeneutics Stack Exchange"></div><a href="https://hermeneutics.stackexchange.com/questions/48556/1-corinthians-125-who-is-god" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:320 }); posts_hot_network.click({ item_type:2, location:11 })">
                    1 Corinthians 1:25, who is God?
                </a>

            </li>
            <li >
                <div class="favicon favicon-politics" title="Politics Stack Exchange"></div><a href="https://politics.stackexchange.com/questions/54001/has-any-government-throughout-history-banned-foreign-currencies" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:475 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Has any government throughout history banned foreign currencies?
                </a>

            </li>
            <li >
                <div class="favicon favicon-worldbuilding" title="Worldbuilding Stack Exchange"></div><a href="https://worldbuilding.stackexchange.com/questions/178892/can-the-little-princes-planet-actually-exist-in-our-universe" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:579 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Can the Little Prince&#x27;s planet actually exist in our universe?
                </a>

            </li>
            <li >
                <div class="favicon favicon-academia" title="Academia Stack Exchange"></div><a href="https://academia.stackexchange.com/questions/150600/colleague-blames-me-for-not-spotting-typos-when-i-only-reviewed-the-structure-an" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:415 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Colleague blames me for not spotting typos when I only reviewed the structure and content
                </a>

            </li>
            <li >
                <div class="favicon favicon-serverfault" title="Server Fault"></div><a href="https://serverfault.com/questions/1021943/difference-between-network-card-size-and-capacity" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:2 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Difference between network card size and capacity
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-academia" title="Academia Stack Exchange"></div><a href="https://academia.stackexchange.com/questions/150712/how-do-i-ensure-ill-be-able-to-claim-authorship-over-a-math-proof-as-an-amateu" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:415 }); posts_hot_network.click({ item_type:2, location:11 })">
                    How do I ensure I&#x27;ll be able to claim authorship over a math proof, as an amateur math student?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-blender" title="Blender Stack Exchange"></div><a href="https://blender.stackexchange.com/questions/183261/joining-two-cylinder-at-45-degree-angle" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:502 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Joining two cylinder at 45 degree angle
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="https://scifi.stackexchange.com/questions/232937/doctor-who-episode-where-the-doctor-met-someone-who-thought-they-were-the-doctor" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Doctor Who episode where the Doctor met someone who thought they were the Doctor
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-physics" title="Physics Stack Exchange"></div><a href="https://physics.stackexchange.com/questions/559744/why-cant-many-models-be-solved-exactly" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:151 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Why can&#x27;t many models be solved exactly?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-literature" title="Literature Stack Exchange"></div><a href="https://literature.stackexchange.com/questions/14640/meaning-of-the-humility-of-a-charge-in-the-chief-mourner-of-marne" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:668 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Meaning of &quot;the humility of a charge&quot; in &quot;The Chief Mourner of Marne&quot;?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-english" title="English Language &amp; Usage Stack Exchange"></div><a href="https://english.stackexchange.com/questions/538030/is-there-a-word-for-automatic-with-negative-connotations" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:97 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Is there a word for &quot;automatic&quot; with negative connotations?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-apple" title="Ask Different"></div><a href="https://apple.stackexchange.com/questions/394064/does-apple-make-backups-of-icloud" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:118 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Does Apple make backups of iCloud?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-space" title="Space Exploration Stack Exchange"></div><a href="https://space.stackexchange.com/questions/44877/what-were-the-first-soviet-spacecraft-to-use-an-internal-docking-tunnel" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:508 }); posts_hot_network.click({ item_type:2, location:11 })">
                    What were the first Soviet spacecraft to use an internal docking tunnel?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="https://scifi.stackexchange.com/questions/232964/was-there-a-scene-where-frodos-elven-cloak-was-shown-to-keep-him-warm-while-he" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Was there a scene where Frodo&#x27;s Elven cloak was shown to keep him warm while he feels cold
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-physics" title="Physics Stack Exchange"></div><a href="https://physics.stackexchange.com/questions/560328/is-the-bohr-radius-deprecated" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:151 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Is the Bohr radius deprecated?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-space" title="Space Exploration Stack Exchange"></div><a href="https://space.stackexchange.com/questions/44875/how-was-the-buran-launch-stack-assembled" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:508 }); posts_hot_network.click({ item_type:2, location:11 })">
                    How was the Buran launch stack assembled?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-matheducators" title="Mathematics Educators Stack Exchange"></div><a href="https://matheducators.stackexchange.com/questions/18463/what-websites-allow-students-to-purchase-solutions-to-problem" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:548 }); posts_hot_network.click({ item_type:2, location:11 })">
                    What websites allow students to purchase solutions to problem?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-aviation" title="Aviation Stack Exchange"></div><a href="https://aviation.stackexchange.com/questions/78946/why-do-helicopter-operations-avoid-ifr" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:528 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Why do helicopter operations avoid IFR?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-electronics" title="Electrical Engineering Stack Exchange"></div><a href="https://electronics.stackexchange.com/questions/506349/art-of-electronics-2-5-transistor-saturation" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:135 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Art of Electronics 2.5 - Transistor saturation
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-worldbuilding" title="Worldbuilding Stack Exchange"></div><a href="https://worldbuilding.stackexchange.com/questions/178928/feasibility-of-energy-absorbing-shields" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:579 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Feasibility of Energy-Absorbing Shields
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-academia" title="Academia Stack Exchange"></div><a href="https://academia.stackexchange.com/questions/150644/i-received-an-allegation-of-academic-misconduct-from-my-university-what-should" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:415 }); posts_hot_network.click({ item_type:2, location:11 })">
                    I received an allegation of academic misconduct from my university. What should I do?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-boardgames" title="Board &amp; Card Games Stack Exchange"></div><a href="https://boardgames.stackexchange.com/questions/51478/what-happens-if-a-permanent-is-made-to-gain-and-then-lose-an-ability-or-vice-ve" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:147 }); posts_hot_network.click({ item_type:2, location:11 })">
                    What happens if a permanent is made to gain and then lose an ability, or vice versa?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="https://scifi.stackexchange.com/questions/233023/which-technologies-depicted-in-the-various-star-trek-series-over-the-past-few-de" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Which technologies depicted in the various Star Trek series over the past few decades have been realized to-date?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-diy" title="Home Improvement Stack Exchange"></div><a href="https://diy.stackexchange.com/questions/195517/any-special-precautions-when-turning-off-water-to-a-property" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:73 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Any special precautions when turning off water to a property?
                </a>

            </li>
    </ul>

        <a href="#" 
           class="show-more js-show-more js-gps-track" 
           data-gps-track="posts_hot_network.click({ item_type:3, location:11 })">
            more hot questions
        </a>
</div>

                            <div id="feed-link" class="js-feed-link">
        <a href="/feeds/question/1732348" title="Feed of this question and its answers">
            <svg aria-hidden="true" class="fc-orange-400 svg-icon iconRss" width="18" height="18" viewBox="0 0 18 18"><path d="M1 3c0-1.1.9-2 2-2h12a2 2 0 012 2v12a2 2 0 01-2 2H3a2 2 0 01-2-2V3zm14.5 12C15.5 8.1 9.9 2.5 3 2.5V5a10 10 0 0110 10h2.5zm-5 0A7.5 7.5 0 003 7.5V10a5 5 0 015 5h2.5zm-5 0A2.5 2.5 0 003 12.5V15h2.5z"/></svg>
            Question feed
        </a>
    </div>
    <aside class="s-modal js-feed-link-modal" tabindex="-1" role="dialog" aria-labelledby="feed-modal-title" aria-describedby="feed-modal-description" aria-hidden="true">
        <div class="s-modal--dialog js-modal-dialog wmx4" role="document"  data-controller="se-draggable">
            <h1 class="s-modal--header fw-bold js-first-tabbable" id="feed-modal-title" data-target="se-draggable.handle" tabindex="0">
                Subscribe to RSS
            </h1>
            <div class="grid gs4 gsy fd-column">
                <div class="grid--cell">
                    <label class="d-block s-label c-default" for="feed-url">
                        Question feed
                        <p class="s-description mt2" id="feed-modal-description">To subscribe to this RSS feed, copy and paste this URL into your RSS reader.</p>
                    </label>
                </div>
                <div class="grid ps-relative">
                    <input class="s-input" type="text" name="feed-url" id="feed-url" readonly="readonly" value="https://stackoverflow.com/feeds/question/1732348" />
                    <svg aria-hidden="true" class="s-input-icon fc-orange-400 svg-icon iconRss" width="18" height="18" viewBox="0 0 18 18"><path d="M1 3c0-1.1.9-2 2-2h12a2 2 0 012 2v12a2 2 0 01-2 2H3a2 2 0 01-2-2V3zm14.5 12C15.5 8.1 9.9 2.5 3 2.5V5a10 10 0 0110 10h2.5zm-5 0A7.5 7.5 0 003 7.5V10a5 5 0 015 5h2.5zm-5 0A2.5 2.5 0 003 12.5V15h2.5z"/></svg>
                </div>
            </div>
            <a class="s-modal--close s-btn s-btn__muted js-modal-close js-last-tabbable" href="#" aria-label="Close">
                <svg aria-hidden="true" class="svg-icon iconClearSm" width="14" height="14" viewBox="0 0 14 14"><path d="M12 3.41L10.59 2 7 5.59 3.41 2 2 3.41 5.59 7 2 10.59 3.41 12 7 8.41 10.59 12 12 10.59 8.41 7 12 3.41z"/></svg>
            </a>
        </div>
    </aside>

            </div>
    </div>
<script>StackExchange.ready(function(){$.get('/posts/1732348/ivc/cf7b');});</script>
<noscript><div><img src="/posts/1732348/ivc/cf7b" class="dno" alt="" width="0" height="0"></div></noscript><div style="display:none" id="prettify-lang">lang-html</div></div>


        </div>
    </div>
        
<script>;try{(function(a){function b(a){return'string'==typeof a?document.getElementById(a):a}function c(a){return a=b(a),!!a&&'none'===getComputedStyle(a).display}function d(a){return!c(a)}function e(a){return!!a}function f(a){return /^\s*$/.test(b(a).innerHTML)}function g(a){var b=a.style;b.height=b.maxHeight=b.minHeight='auto',b.display='none',[].forEach.call(a.children,g)}function h(a,b){var c;return function(){return a&&(c=a.call(b||this,arguments),a=null),c}}function i(a){var b=document.createElement('script');b.src=a,document.body.appendChild(b)}function j(a){return k([],a)}function k(a,b){return a.push=function(a){return b(),delete this.push,this.push(a)},a}function l(){try{return!new Function('return async()=>{};')}catch(a){return!0}}function m(){return'undefined'!=typeof googletag&&!!googletag.apiReady}function n(){m()||(googletag={cmd:j(A)})}function o(){var a=document.createElement('div');a.className='adsbox',a.id='clc-abd',a.style.position='absolute',a.style.pointerEvents='none',a.innerHTML='&nbsp;',document.body.appendChild(a)}function p(){return Object.keys(E.ids)}function r(a){var b=E.ids[a],c=E.slots[b];'function'==typeof c&&(c=c(a));return{path:'/'+B+'/'+D+'/'+b+'/'+C,sizes:c,zone:b}}function q(a){try{Array.isArray(clc.dfp.slotsRenderedEvents)||(clc.dfp.slotsRenderedEvents=[]),clc.dfp.slotsRenderedEvents.push(a);var b=a.slot.getSlotElementId(),c=[];b||c.push('id=0');var d=document.getElementById(b);if(!b||d?d.hasAttribute('data-clc-stalled')&&c.push('st=1'):c.push('el=0'),0!==c.length)return void F(c.join('&'));var e=r(b),f=e.zone;if(clc.collapse&&clc.collapse[f]&&a.isEmpty)return g(d),void d.setAttribute('data-clc-ready','true');if(-1!==x.dh.indexOf(a.lineItemId))g(d);else if(a.lineItemId&&(d.setAttribute('data-clc-prefilled','true'),'dfp-msb'==b)){var h=document.getElementById('hireme');g(h)}d.setAttribute('data-clc-ready','true')}catch(a){var i=document.querySelector('#dfp-tsb, #dfp-isb, #clc-tsb');i&&i.setAttribute('data-clc-ready','true'),F('e=1')}}function s(a){return!(clc.collapse&&void 0!==clc.collapse[a])||!!clc.collapse[a]}function t(a,b){'dfp-isb'===a&&b.setTargeting('Sidebar',['Inline']),'dfp-tsb'===a&&b.setTargeting('Sidebar',['Right']);var c=r(a),d=c.path,e=c.sizes,f=c.zone,g=googletag.defineSlot(d,e,a);if(s(f)){var h=!x.ll;g.setCollapseEmptyDiv(!0,h)}g.addService(b),!1}function u(b){var c=a.dfp&&a.dfp.targeting||{};'SystemDefault'===c.ProductVariant&&(window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches?c.ProductVariant='Dark':c.ProductVariant='Light'),Object.keys(c).forEach(function(a){b.setTargeting(a,c[a])})}function v(a){var g=a.map(b).filter(e);return{eligible:g.filter(f).filter(d),ineligible:g.filter(c)}}function w(b){void 0===b&&(b=p());var c=['dfp-mlb','dfp-smlb'];if(!m())return n(),void googletag.cmd.push(function(){return w(b)});var d=v(b),e=d.eligible,f=d.ineligible;if(f.forEach(g),0!==e.length){x.abd&&o(),googletag.destroySlots();var h=googletag.pubads();x.sf&&(h.setForceSafeFrame(!0),h.setSafeFrameConfig({allowOverlayExpansion:!0,allowPushExpansion:!0,sandbox:!0})),x.ll||h.enableSingleRequest(),a.sreEvent||(h.addEventListener('slotRenderEnded',q),a.sreEvent=!0),u(h);var i=e.filter(function(a){return!x.ll||0>c.indexOf(a.id)}),j=e.filter(function(a){return!!x.ll&&0<=c.indexOf(a.id)});i.forEach(function(a){t(a.id,h),a.setAttribute('data-dfp-zone','true')}),googletag.enableServices(),i.forEach(function(a){googletag.display(a.id)}),x.ll&&(h.enableLazyLoad({fetchMarginPercent:0,renderMarginPercent:0}),j.forEach(function(a){t(a.id,h),a.setAttribute('data-clc-prefilled','true')}),j.forEach(function(a){googletag.display(a.id)}))}}var x=function(a){for(var b=[],c=1;c<arguments.length;c++)b[c-1]=arguments[c];for(var d,e=0,f=b;e<f.length;e++)for(var g in d=f[e],d)a[g]=d[g];return a}({"lib":"https://cdn.sstatic.net/clc/clc.min.js?v=7dce99576e19","style":"https://cdn.sstatic.net/clc/styles/clc.min.css?v=ac5522400b2d","u":"https://clc.stackoverflow.com/markup.js","wa":true,"kt":2000,"tto":true,"h":"clc.stackoverflow.com","allowed":"^(((talent\\.)?stackoverflow)|(blog\\.codinghorror)|(serverfault|askubuntu)|([^\\.]+\\.stackexchange))\\.com$","wv":true,"al":false,"dh":[5171832659],"abd":true},a.options||{}),y=h(function(){var a=x.lib;l()&&(a=a.replace(/(\.min)?\.js(\?v=[0-9a-fA-F]+)?$/,'.ie$1.js$2')),i(a)}),z=a.cmd||[];Array.isArray(z)&&(0<z.length?y():k(z,y));var A=h(function(){i('https://www.googletagservices.com/tag/js/gpt.js')}),B='248424177',C=/^\/tags\//.test(location.pathname)||/^\/questions\/tagged\//.test(location.pathname)?'tag-pages':/^\/$/.test(location.pathname)||/^\/home/.test(location.pathname)?'home-page':'question-pages',D=location.hostname;var E={slots:{lb:[[728,90]],mlb:[[728,90]],smlb:[[728,90]],bmlb:[[728,90]],sb:function(a){return'dfp-tsb'===a?[[300,250],[300,600]]:[[300,250]]},"tag-sponsorship":[[730,135]],"mobile-below-question":[[320,50],[300,250]],msb:[[300,250],[300,600]]},ids:{"dfp-tlb":'lb',"dfp-mlb":'mlb',"dfp-smlb":'smlb',"dfp-bmlb":'bmlb',"dfp-tsb":'sb',"dfp-isb":'sb',"dfp-tag":'tag-sponsorship',"dfp-msb":'msb',"dfp-m-aq":'mobile-below-question',"clc-tlb":'lb',"clc-mlb":'mlb',"clc-tsb":'sb'}},F=function(a){new Image().src='https://'+x.h+'/stalled.gif?'+a};(function(){var b=x.al;b&&z.push(function(){return a.load()})})(),n(),a.dfp={load:w},a.options=x,a.cmd=z})(this.clc=this.clc||{})}catch(a){window.console.error(a)}</script>    <script>
        var clc = clc || {};
        clc.collapse = { sb: !0, 'tag-sponsorship': !0, lb:!0, mlb:!0, smlb:!0, bmlb:!0, 'mobile-below-question':!0};
        clc.options = clc.options || {};
        clc.options.sf = !0;
        clc.options.hb = !1;
        clc.options.ll = !0;
        clc.cmd = clc.cmd || [];
        clc.cmd.push(function () { window.clc_request='AqJcTlB5FNgIAAAAAPxuGgACAAAAAgAAAAASAAAAfGh0bWx8cmVnZXh8eGh0bWx8ANhcR7cviYIAlU4'; clc.load(); });
        clc.dfp = clc.dfp || {};
        clc.dfp.targeting = {Registered:['false'],'so-tag':['html','regex','xhtml'],'tag-reportable':['html','regex','xhtml'],'tag-non-reportable':['html','regex','xhtml'],NumberOfAnswers:['20-plus']};
        var googletag = googletag || {};
        googletag.cmd = googletag.cmd || [];
        googletag.cmd.push(function () { clc.dfp.load(); });

    </script>

            <footer id="footer" class="site-footer js-footer" role="contentinfo">
        <div class="site-footer--container">
                <div class="site-footer--logo">
                    
                    <a href="https://stackoverflow.com"><svg aria-hidden="true" class="native svg-icon iconLogoGlyphMd" width="32" height="37" viewBox="0 0 32 37"><path d="M26 33v-9h4v13H0V24h4v9h22z" fill="#BCBBBB"/><path d="M21.5 0l-2.7 2 9.9 13.3 2.7-2L21.5 0zM26 18.4L13.3 7.8l2.1-2.5 12.7 10.6-2.1 2.5zM9.1 15.2l15 7 1.4-3-15-7-1.4 3zm14 10.79l.68-2.95-16.1-3.35L7 23l16.1 2.99zM23 30H7v-3h16v3z" fill="#F48024"/></svg></a>
                </div>
            <nav class="site-footer--nav">
                    <div class="site-footer--col site-footer--col__visible js-footer-col" data-name="default">
                        <h5 class="-title"><a href="https://stackoverflow.com" class="js-gps-track" data-gps-track="footer.click({ location: 2, link: 15})">Stack Overflow</a></h5>
                        <ul class="-list js-primary-footer-links">
                            <li class="-item"><a href="/questions" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 16})">Questions</a></li>
                                <li class="-item"><a href="https://stackoverflow.com/jobs" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 17})">Jobs</a></li>
                                <li class="-item"><a href="https://stackoverflow.com/jobs/directory/developer-jobs" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 11})">Developer Jobs Directory</a></li>
                                     <li class="-item"><a href="https://stackoverflow.com/jobs/salary" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 28})">Salary Calculator</a></li>
                                <li class="-item"><a href="/help" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 3 })">Help</a></li>
                                <li class="-item"><a onclick='StackExchange.switchMobile("on")' class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 12 })">Mobile</a></li>
                        </ul>
                    </div>
                    <div class="site-footer--col site-footer--col__visible js-footer-col" data-name="default">
                        <h5 class="-title"><a href="https://stackoverflowbusiness.com" class="js-gps-track" data-gps-track="footer.click({ location: 2, link: 19 })">Products</a></h5>
                        <ul class="-list">
                            <li class="-item"><a href="https://stackoverflow.com/teams" class="js-gps-track -link" 
                                                 data-ga="[&quot;teams traffic&quot;,&quot;footer - site nav&quot;,&quot;stackoverflow.com/teams&quot;,null,{&quot;dimension4&quot;:&quot;teams&quot;}]"
                                                 data-gps-track="footer.click({ location: 2, link: 29 })">Teams</a></li>
                            <li class="-item"><a href="https://stackoverflow.com/talent" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 20 })">Talent</a></li>
                            <li class="-item"><a href="https://stackoverflow.com/advertising" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 21 })">Advertising</a></li>
                            <li class="-item"><a href="https://stackoverflow.com/enterprise" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 22 })">Enterprise</a></li>
                        </ul>
                    </div>
                <div class="site-footer--col site-footer--col__visible js-footer-col" data-name="default">
                    <h5 class="-title"><a class="js-gps-track" data-gps-track="footer.click({ location: 2, link: 1 })" href="https://stackoverflow.com/company/about">Company</a></h5>
                    <ul class="-list">
                            <li class="-item"><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 1 })" href="https://stackoverflow.com/company/about">About</a></li>
                        <li class="-item"><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 27 })" href="https://stackoverflow.com/company/press">Press</a></li>
                            <li class="-item"><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 9 })" href="https://stackoverflow.com/company/work-here">Work Here</a></li>
                        <li class="-item"><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 7 })" href="https://stackoverflow.com/legal">Legal</a></li>
                        <li class="-item"><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 8 })" href="https://stackoverflow.com/legal/privacy-policy">Privacy Policy</a></li>
                            <li class="-item"><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 13 })" href="https://stackoverflow.com/company/contact">Contact Us</a></li>
                    </ul>
                </div>
                <div class="site-footer--col site-footer--categories-nav site-footer--col__visible">
                    <a href="#" class="site-footer--back js-footer-back"><svg aria-hidden="true" class="svg-icon iconArrowLeftAlt" width="18" height="18" viewBox="0 0 18 18"><path d="M10.58 16L12 14.59 6.4 9 12 3.41 10.57 2l-7 7 7 7z"/></svg></a>
                    <div>
                        <h5 class="-title"><a href="https://stackexchange.com" data-gps-track="footer.click({ location: 2, link: 30 })">Stack Exchange<br> Network</a></h5>
                        <ul class="-list">
                            <li class="-item"><a href="#" class="-link _expandable js-footer-category-trigger js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })" data-target="Technology">Technology</a></li>
                            <li class="-item"><a href="#" class="-link _expandable js-footer-category-trigger js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })" data-target="Life / Arts">Life / Arts</a></li>
                            <li class="-item"><a href="#" class="-link _expandable js-footer-category-trigger js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })" data-target="Culture / Recreation">Culture / Recreation</a></li>
                            <li class="-item"><a href="#" class="-link _expandable js-footer-category-trigger js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })" data-target="Science">Science</a></li>
                            <li class="-item"><a href="#" class="-link _expandable js-footer-category-trigger js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })" data-target="Other">Other</a></li>
                        </ul>
                    </div>
                </div>
                <div class="site-footer--categories">
                        <div class="site-footer--col site-footer--category js-footer-col" data-name="Technology">
        <ul class="-list">
                <li class="-item"><a href="https://stackoverflow.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professional and enthusiast programmers">Stack Overflow</a></li>
                <li class="-item"><a href="https://serverfault.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="system and network administrators">Server Fault</a></li>
                <li class="-item"><a href="https://superuser.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="computer enthusiasts and power users">Super User</a></li>
                <li class="-item"><a href="https://webapps.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="power users of web applications">Web Applications</a></li>
                <li class="-item"><a href="https://askubuntu.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="Ubuntu users and developers">Ask Ubuntu</a></li>
                <li class="-item"><a href="https://webmasters.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="pro webmasters">Webmasters</a></li>
                <li class="-item"><a href="https://gamedev.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professional and independent game developers">Game Development</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Technology"><ul class="-list">
                <li class="-item"><a href="https://tex.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="users of TeX, LaTeX, ConTeXt, and related typesetting systems">TeX - LaTeX</a></li>
                <li class="-item"><a href="https://softwareengineering.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professionals, academics, and students working within the systems development life cycle">Software Engineering</a></li>
                <li class="-item"><a href="https://unix.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="users of Linux, FreeBSD and other Un*x-like operating systems">Unix &amp; Linux</a></li>
                <li class="-item"><a href="https://apple.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="power users of Apple hardware and software">Ask Different (Apple)</a></li>
                <li class="-item"><a href="https://wordpress.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="WordPress developers and administrators">WordPress Development</a></li>
                <li class="-item"><a href="https://gis.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="cartographers, geographers and GIS professionals">Geographic Information Systems</a></li>
                <li class="-item"><a href="https://electronics.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="electronics and electrical engineering professionals, students, and enthusiasts">Electrical Engineering</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Technology"><ul class="-list">
                <li class="-item"><a href="https://android.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="enthusiasts and power users of the Android operating system">Android Enthusiasts</a></li>
                <li class="-item"><a href="https://security.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="information security professionals">Information Security</a></li>
                <li class="-item"><a href="https://dba.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="database professionals who wish to improve their database skills and learn from others in the community">Database Administrators</a></li>
                <li class="-item"><a href="https://drupal.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="Drupal developers and administrators">Drupal Answers</a></li>
                <li class="-item"><a href="https://sharepoint.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="SharePoint enthusiasts">SharePoint</a></li>
                <li class="-item"><a href="https://ux.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="user experience researchers and experts">User Experience</a></li>
                <li class="-item"><a href="https://mathematica.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="users of Wolfram Mathematica">Mathematica</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Technology"><ul class="-list">
                <li class="-item"><a href="https://salesforce.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="Salesforce administrators, implementation experts, developers and anybody in-between">Salesforce</a></li>
                <li class="-item"><a href="https://expressionengine.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="administrators, end users, developers and designers for ExpressionEngine&#xAE; CMS">ExpressionEngine&#xAE; Answers</a></li>
                <li class="-item"><a href="https://pt.stackoverflow.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="programadores profissionais e entusiastas">Stack Overflow em Portugu&#xEA;s</a></li>
                <li class="-item"><a href="https://blender.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people who use Blender to create 3D graphics, animations, or games">Blender</a></li>
                <li class="-item"><a href="https://networkengineering.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="network engineers">Network Engineering</a></li>
                <li class="-item"><a href="https://crypto.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="software developers, mathematicians and others interested in cryptography">Cryptography</a></li>
                <li class="-item"><a href="https://codereview.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="peer programmer code reviews">Code Review</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Technology"><ul class="-list">
                <li class="-item"><a href="https://magento.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="users of the Magento e-Commerce platform">Magento</a></li>
                <li class="-item"><a href="https://softwarerecs.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people seeking specific software recommendations">Software Recommendations</a></li>
                <li class="-item"><a href="https://dsp.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="practitioners of the art and science of signal, image and video processing">Signal Processing</a></li>
                <li class="-item"><a href="https://emacs.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="those using, extending or developing Emacs">Emacs</a></li>
                <li class="-item"><a href="https://raspberrypi.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="users and developers of hardware and software for Raspberry Pi">Raspberry Pi</a></li>
                <li class="-item"><a href="https://ru.stackoverflow.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="&#x43F;&#x440;&#x43E;&#x433;&#x440;&#x430;&#x43C;&#x43C;&#x438;&#x441;&#x442;&#x43E;&#x432;">Stack Overflow &#x43D;&#x430; &#x440;&#x443;&#x441;&#x441;&#x43A;&#x43E;&#x43C;</a></li>
                <li class="-item"><a href="https://codegolf.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="programming puzzle enthusiasts and code golfers">Code Golf</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Technology"><ul class="-list">
                <li class="-item"><a href="https://es.stackoverflow.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="programadores y profesionales de la inform&#xE1;tica">Stack Overflow en espa&#xF1;ol</a></li>
                <li class="-item"><a href="https://ethereum.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="users of Ethereum, the decentralized application platform and smart contract enabled blockchain">Ethereum</a></li>
                <li class="-item"><a href="https://datascience.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="Data science professionals, Machine Learning specialists, and those interested in learning more about the field">Data Science</a></li>
                <li class="-item"><a href="https://arduino.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="developers of open-source hardware and software that is compatible with Arduino">Arduino</a></li>
                <li class="-item"><a href="https://bitcoin.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="Bitcoin crypto-currency enthusiasts">Bitcoin</a></li>
                <li class="-item"><a href="https://sqa.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="software quality control experts, automation engineers, and software testers">Software Quality Assurance &amp; Testing</a></li>
                <li class="-item"><a href="https://sound.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="sound engineers, producers, editors, and enthusiasts">Sound Design</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Technology"><ul class="-list">
                <li class="-item"><a href="https://windowsphone.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="enthusiasts and power users of Windows Phone OS">Windows Phone</a></li>
                <li class="-item">
                    <a href="https://stackexchange.com/sites#technology" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 26 })">
                        <strong>
                            more (28)
                        </strong>
                    </a>
                </li>
        </ul>
    </div>
    <div class="site-footer--col site-footer--category js-footer-col" data-name="Life / Arts">
        <ul class="-list">
                <li class="-item"><a href="https://photo.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professional, enthusiast and amateur photographers">Photography</a></li>
                <li class="-item"><a href="https://scifi.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="science fiction and fantasy enthusiasts">Science Fiction &amp; Fantasy</a></li>
                <li class="-item"><a href="https://graphicdesign.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="Graphic Design professionals, students, and enthusiasts">Graphic Design</a></li>
                <li class="-item"><a href="https://movies.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="movie and TV enthusiasts">Movies &amp; TV</a></li>
                <li class="-item"><a href="https://music.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="musicians, students, and enthusiasts">Music: Practice &amp; Theory</a></li>
                <li class="-item"><a href="https://worldbuilding.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="writers/artists using science, geography and culture to construct imaginary worlds and settings">Worldbuilding</a></li>
                <li class="-item"><a href="https://video.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation">Video Production</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Life / Arts"><ul class="-list">
                <li class="-item"><a href="https://cooking.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professional and amateur chefs">Seasoned Advice (cooking)</a></li>
                <li class="-item"><a href="https://diy.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="contractors and serious DIYers">Home Improvement</a></li>
                <li class="-item"><a href="https://money.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people who want to be financially literate">Personal Finance &amp; Money</a></li>
                <li class="-item"><a href="https://academia.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="academics and those enrolled in higher education">Academia</a></li>
                <li class="-item"><a href="https://law.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="legal professionals, students, and others with experience or interest in law">Law</a></li>
                <li class="-item"><a href="https://fitness.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="physical fitness professionals, athletes, trainers, and those providing health-related needs">Physical Fitness</a></li>
                <li class="-item"><a href="https://gardening.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="gardeners and landscapers">Gardening &amp; Landscaping</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Life / Arts"><ul class="-list">
                <li class="-item"><a href="https://parenting.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="parents, grandparents, nannies and others with a parenting role">Parenting</a></li>
                <li class="-item">
                    <a href="https://stackexchange.com/sites#lifearts" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 26 })">
                        <strong>
                            more (10)
                        </strong>
                    </a>
                </li>
        </ul>
    </div>
    <div class="site-footer--col site-footer--category js-footer-col" data-name="Culture / Recreation">
        <ul class="-list">
                <li class="-item"><a href="https://english.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="linguists, etymologists, and serious English language enthusiasts">English Language &amp; Usage</a></li>
                <li class="-item"><a href="https://skeptics.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="scientific skepticism">Skeptics</a></li>
                <li class="-item"><a href="https://judaism.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="those who base their lives on Jewish law and tradition and anyone interested in learning more">Mi Yodeya (Judaism)</a></li>
                <li class="-item"><a href="https://travel.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="road warriors and seasoned travelers">Travel</a></li>
                <li class="-item"><a href="https://christianity.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="committed Christians, experts in Christianity and those interested in learning more">Christianity</a></li>
                <li class="-item"><a href="https://ell.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="speakers of other languages learning English">English Language Learners</a></li>
                <li class="-item"><a href="https://japanese.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="students, teachers, and linguists wanting to discuss the finer points of the Japanese language">Japanese Language</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Culture / Recreation"><ul class="-list">
                <li class="-item"><a href="https://chinese.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="students, teachers, and linguists wanting to discuss the finer points of the Chinese language">Chinese Language</a></li>
                <li class="-item"><a href="https://french.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="students, teachers, and linguists wanting to discuss the finer points of the French language">French Language</a></li>
                <li class="-item"><a href="https://german.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="speakers of German wanting to discuss the finer points of the language and translation">German Language</a></li>
                <li class="-item"><a href="https://hermeneutics.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professors, theologians, and those interested in exegetical analysis of biblical texts">Biblical Hermeneutics</a></li>
                <li class="-item"><a href="https://history.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="historians and history buffs">History</a></li>
                <li class="-item"><a href="https://spanish.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="linguists, teachers, students and Spanish language enthusiasts in general wanting to discuss the finer points of the language">Spanish Language</a></li>
                <li class="-item"><a href="https://islam.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="Muslims, experts in Islam, and those interested in learning more about Islam">Islam</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Culture / Recreation"><ul class="-list">
                <li class="-item"><a href="https://rus.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="&#x43B;&#x438;&#x43D;&#x433;&#x432;&#x438;&#x441;&#x442;&#x43E;&#x432; &#x438; &#x44D;&#x43D;&#x442;&#x443;&#x437;&#x438;&#x430;&#x441;&#x442;&#x43E;&#x432; &#x440;&#x443;&#x441;&#x441;&#x43A;&#x43E;&#x433;&#x43E; &#x44F;&#x437;&#x44B;&#x43A;&#x430;">&#x420;&#x443;&#x441;&#x441;&#x43A;&#x438;&#x439; &#x44F;&#x437;&#x44B;&#x43A;</a></li>
                <li class="-item"><a href="https://russian.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="students, teachers, and linguists wanting to discuss the finer points of the Russian language">Russian Language</a></li>
                <li class="-item"><a href="https://gaming.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="passionate videogamers on all platforms">Arqade (gaming)</a></li>
                <li class="-item"><a href="https://bicycles.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people who build and repair bicycles, people who train cycling, or commute on bicycles">Bicycles</a></li>
                <li class="-item"><a href="https://rpg.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="gamemasters and players of tabletop, paper-and-pencil role-playing games">Role-playing Games</a></li>
                <li class="-item"><a href="https://anime.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="anime and manga fans">Anime &amp; Manga</a></li>
                <li class="-item"><a href="https://puzzling.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="those who create, solve, and study puzzles">Puzzling</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Culture / Recreation"><ul class="-list">
                <li class="-item"><a href="https://mechanics.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="mechanics and DIY enthusiast owners of cars, trucks, and motorcycles">Motor Vehicle Maintenance &amp; Repair</a></li>
                <li class="-item"><a href="https://boardgames.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people who like playing board games, designing board games or modifying the rules of existing board games">Board &amp; Card Games</a></li>
                <li class="-item"><a href="https://bricks.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="LEGO&#xAE; and building block enthusiasts">Bricks</a></li>
                <li class="-item"><a href="https://homebrew.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="dedicated home brewers and serious enthusiasts">Homebrewing</a></li>
                <li class="-item"><a href="https://martialarts.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="students and teachers of all martial arts">Martial Arts</a></li>
                <li class="-item"><a href="https://outdoors.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people who love being outdoors enjoying nature and wilderness, and learning about the required skills and equipment">The Great Outdoors</a></li>
                <li class="-item"><a href="https://poker.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="serious players and enthusiasts of poker">Poker</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Culture / Recreation"><ul class="-list">
                <li class="-item"><a href="https://chess.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="serious players and enthusiasts of chess">Chess</a></li>
                <li class="-item"><a href="https://sports.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="participants in team and individual sport activities">Sports</a></li>
                <li class="-item">
                    <a href="https://stackexchange.com/sites#culturerecreation" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 26 })">
                        <strong>
                            more (16)
                        </strong>
                    </a>
                </li>
        </ul>
    </div>
    <div class="site-footer--col site-footer--category js-footer-col" data-name="Science">
        <ul class="-list">
                <li class="-item"><a href="https://mathoverflow.net" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professional mathematicians">MathOverflow</a></li>
                <li class="-item"><a href="https://math.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people studying math at any level and professionals in related fields">Mathematics</a></li>
                <li class="-item"><a href="https://stats.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="people interested in statistics, machine learning, data analysis, data mining, and data visualization">Cross Validated (stats)</a></li>
                <li class="-item"><a href="https://cstheory.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="theoretical computer scientists and researchers in related fields">Theoretical Computer Science</a></li>
                <li class="-item"><a href="https://physics.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="active researchers, academics and students of physics">Physics</a></li>
                <li class="-item"><a href="https://chemistry.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="scientists, academics, teachers, and students in the field of chemistry">Chemistry</a></li>
                <li class="-item"><a href="https://biology.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="biology researchers, academics, and students">Biology</a></li>
                    </ul></div><div class="site-footer--col site-footer--category js-footer-col" data-name="Science"><ul class="-list">
                <li class="-item"><a href="https://cs.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="students, researchers and practitioners of computer science">Computer Science</a></li>
                <li class="-item"><a href="https://philosophy.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="those interested in the study of the fundamental nature of knowledge, reality, and existence">Philosophy</a></li>
                <li class="-item"><a href="https://linguistics.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="professional linguists and others with an interest in linguistic research and theory">Linguistics</a></li>
                <li class="-item"><a href="https://psychology.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="practitioners, researchers, and students in cognitive science, psychology, neuroscience, and psychiatry">Psychology &amp; Neuroscience</a></li>
                <li class="-item"><a href="https://scicomp.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="scientists using computers to solve scientific problems">Computational Science</a></li>
                <li class="-item">
                    <a href="https://stackexchange.com/sites#science" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 26 })">
                        <strong>
                            more (10)
                        </strong>
                    </a>
                </li>
        </ul>
    </div>
    <div class="site-footer--col site-footer--category js-footer-col" data-name="Other">
        <ul class="-list">
                <li class="-item"><a href="https://meta.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="meta-discussion of the Stack Exchange family of Q&amp;A websites">Meta Stack Exchange</a></li>
                <li class="-item"><a href="https://stackapps.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="apps, scripts, and development with the Stack Exchange API">Stack Apps</a></li>
                <li class="-item"><a href="https://api.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="programmatic interaction with Stack Exchange sites">API</a></li>
                <li class="-item"><a href="https://data.stackexchange.com" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 25 })" title="querying Stack Exchange data using SQL">Data</a></li>
        </ul>
    </div>

                </div>
            </nav>
            <div class="site-footer--copyright fs-fine">
                <ul class="-list">
                    <li class="-item"><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link:4 })" href="https://stackoverflow.blog?blb=1">Blog</a></li>
                    <li class="-item"><a href="https://www.facebook.com/officialstackoverflow/" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 31 })">Facebook</a></li>
                    <li class="-item"><a href="https://twitter.com/stackoverflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 32 })">Twitter</a></li>
                    <li class="-item"><a href="https://linkedin.com/company/stack-overflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 33 })">LinkedIn</a></li>
                    <li class="-item"><a href="https://www.instagram.com/thestackoverflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 36 })">Instagram</a></li>
                </ul>

                <p class="mt-auto mb24">
site design / logo &#169; 2020 Stack Exchange Inc; user contributions licensed under <a href="https://stackoverflow.com/help/licensing">cc by-sa</a>.                    <span id="svnrev">rev&nbsp;2020.6.18.37100</span>
                </p>
            </div>
        </div>

    </footer>

            <script>StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); })</script>
    <noscript>
        <div id="noscript-warning">Stack Overflow works best with JavaScript enabled
            <img src="https://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno">
        </div>
    </noscript>

        <script>
(function(i, s, o, g, r, a, m) {
                i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
                m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m);
            })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

            StackExchange.ready(function () {

                StackExchange.ga.init({
                    sendTitles: true,
                    tracker: window.ga,
                    trackingCodes: [
                        'UA-108242619-1'
                    ],
                        checkDimension: 'dimension42'
                });



                    StackExchange.ga.setDimension('dimension2', '|html|regex|xhtml|');

                    StackExchange.ga.setDimension('dimension3', 'Questions/Show');


                StackExchange.ga.trackPageView();
            });
            /**/

            var _qevents = _qevents || [],
            _comscore = _comscore || [];
            (function() {
                var ssl = 'https:' == document.location.protocol,
                    s = document.getElementsByTagName('script')[0],
                    qc = document.createElement('script');
 qc.async = true;
                    qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js';
                    s.parentNode.insertBefore(qc, s);
                    _qevents.push({ qacct: "p-c1rF4kxgLUzNc" });/**/
 var sc = document.createElement('script');
                    sc.async = true;
                    sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js';
                    s.parentNode.insertBefore(sc, s);
                    _comscore.push({ c1: "2", c2: "17440561" });            })();
            
</script>

    
    </body>
    </html>
